From 44f570708ff0f9a92b420ef1762f901c8e1eda9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 4 May 2023 16:32:04 +0200 Subject: [PATCH] Add extra test cases for string completions --- ...nditionalTypesUsingTemplateLiteralTypes.ts | 5 ++- ...nditionalTypesUsingTemplateLiteralTypes.ts | 35 +++++++++++++++++++ ...eralCompletionsInPositionTypedUsingRest.ts | 21 +++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/stringLiteralCompletionsFromGenericConditionalTypesUsingTemplateLiteralTypes.ts create mode 100644 tests/cases/fourslash/stringLiteralCompletionsInPositionTypedUsingRest.ts diff --git a/tests/cases/fourslash/stringLiteralCompletionsForGenericConditionalTypesUsingTemplateLiteralTypes.ts b/tests/cases/fourslash/stringLiteralCompletionsForGenericConditionalTypesUsingTemplateLiteralTypes.ts index 5c63857b2feaa..0074976300ce3 100644 --- a/tests/cases/fourslash/stringLiteralCompletionsForGenericConditionalTypesUsingTemplateLiteralTypes.ts +++ b/tests/cases/fourslash/stringLiteralCompletionsForGenericConditionalTypesUsingTemplateLiteralTypes.ts @@ -1,8 +1,7 @@ /// -// NOTE: Test pulled from https://github.com/microsoft/TypeScript/pull/52997 +// repro from https://github.com/microsoft/TypeScript/issues/49680 -// @Filename: /a.tsx //// type PathOf = //// K extends `${infer U}.${infer V}` //// ? U extends keyof T ? PathOf : `${P}${keyof T & (string | number)}` @@ -12,4 +11,4 @@ //// //// consumer('b./*ts*/') -verify.completions({ marker: ["ts"], exact: ["a", "b", "b.c"] }); \ No newline at end of file +verify.completions({ marker: ["ts"], exact: ["a", "b", "b.c"] }); diff --git a/tests/cases/fourslash/stringLiteralCompletionsFromGenericConditionalTypesUsingTemplateLiteralTypes.ts b/tests/cases/fourslash/stringLiteralCompletionsFromGenericConditionalTypesUsingTemplateLiteralTypes.ts new file mode 100644 index 0000000000000..c222c615a8886 --- /dev/null +++ b/tests/cases/fourslash/stringLiteralCompletionsFromGenericConditionalTypesUsingTemplateLiteralTypes.ts @@ -0,0 +1,35 @@ +/// + +// @strict: true + +// repro from https://github.com/microsoft/TypeScript/issues/53997 + +//// type keyword = "foo" | "bar" | "baz" +//// +//// type validateString = s extends keyword +//// ? s +//// : s extends `${infer left extends keyword}|${infer right}` +//// ? right extends keyword +//// ? s +//// : `${left}|${keyword}` +//// : keyword +//// +//// type isUnknown = unknown extends t +//// ? [t] extends [{}] +//// ? false +//// : true +//// : false +//// +//// type validate = def extends string +//// ? validateString +//// : isUnknown extends true +//// ? keyword +//// : { +//// [k in keyof def]: validate +//// } +//// const parse = (def: validate) => def +//// const shallowExpression = parse("foo|/*ts*/") +//// const nestedExpression = parse({ prop: "foo|/*ts2*/" }) + +verify.completions({ marker: ["ts"], exact: ["foo", "bar", "baz", "foo|foo", "foo|bar", "foo|baz"] }); +verify.completions({ marker: ["ts2"], exact: ["foo|foo", "foo|bar", "foo|baz"] }); diff --git a/tests/cases/fourslash/stringLiteralCompletionsInPositionTypedUsingRest.ts b/tests/cases/fourslash/stringLiteralCompletionsInPositionTypedUsingRest.ts new file mode 100644 index 0000000000000..bd4a11eac9e00 --- /dev/null +++ b/tests/cases/fourslash/stringLiteralCompletionsInPositionTypedUsingRest.ts @@ -0,0 +1,21 @@ +/// + +// repro from https://github.com/microsoft/TypeScript/issues/49680#issuecomment-1249191842 + +//// declare function pick(obj: T, ...keys: K[]): Pick; +//// declare function pick2(obj: T, ...keys: K): Pick; +//// +//// const obj = { aaa: 1, bbb: '2', ccc: true }; +//// +//// pick(obj, 'aaa', '/*ts1*/'); +//// pick2(obj, 'aaa', '/*ts2*/'); + +// repro from https://github.com/microsoft/TypeScript/issues/49680#issuecomment-1273677941 + +//// class Q { +//// public select(...args: Keys[]) {} +//// } +//// new Q<{ id: string; name: string }>().select("name", "/*ts3*/"); + +verify.completions({ marker: ["ts1", "ts2"], exact: ["aaa", "bbb", "ccc"] }); +verify.completions({ marker: ["ts3"], exact: ["name", "id"] });