From 089876a5c5262e5303e7561335b4369e60449c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 28 Mar 2023 03:21:03 +0200 Subject: [PATCH] Retry string completions from the inferred type by default (#53481) --- src/services/stringCompletions.ts | 2 +- ...onsLiteralFromInferenceWithinInferredType3.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionsLiteralFromInferenceWithinInferredType3.ts diff --git a/src/services/stringCompletions.ts b/src/services/stringCompletions.ts index 14bb8ab48c3..c5c82b3ed25 100644 --- a/src/services/stringCompletions.ts +++ b/src/services/stringCompletions.ts @@ -440,7 +440,7 @@ function getStringLiteralCompletionEntries(sourceFile: SourceFile, node: StringL const literals = contextualTypes.types.filter(literal => !tracker.hasValue(literal.value)); return { kind: StringLiteralCompletionKind.Types, types: literals, isNewIdentifier: false }; default: - return fromContextualType(); + return fromContextualType() || fromContextualType(ContextFlags.None); } function fromContextualType(contextFlags: ContextFlags = ContextFlags.Completions): StringLiteralCompletionsFromTypes | undefined { diff --git a/tests/cases/fourslash/completionsLiteralFromInferenceWithinInferredType3.ts b/tests/cases/fourslash/completionsLiteralFromInferenceWithinInferredType3.ts new file mode 100644 index 00000000000..9cbe1777324 --- /dev/null +++ b/tests/cases/fourslash/completionsLiteralFromInferenceWithinInferredType3.ts @@ -0,0 +1,16 @@ +/// + +//// declare function test(a: { +//// [K in keyof T]: { +//// b?: (keyof T)[]; +//// }; +//// }): void; +//// +//// test({ +//// foo: {}, +//// bar: { +//// b: ["/*ts*/"], +//// }, +//// }); + +verify.completions({ marker: ["ts"], exact: ["foo", "bar"] });