From d95caa51fcf907b8f23d67ce209a6ef7f1d482a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 13 Jun 2023 00:16:08 +0200 Subject: [PATCH] Fixed a regression with string completions not being available directly in arguments typed using rest parameter (#54588) --- src/services/stringCompletions.ts | 2 +- ...letionsLiteralDirectlyInRestConstrainedToArrayType.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionsLiteralDirectlyInRestConstrainedToArrayType.ts diff --git a/src/services/stringCompletions.ts b/src/services/stringCompletions.ts index df0e24e5589..150d0652dd2 100644 --- a/src/services/stringCompletions.ts +++ b/src/services/stringCompletions.ts @@ -388,7 +388,7 @@ function getStringLiteralCompletionEntries(sourceFile: SourceFile, node: StringL // Get string literal completions from specialized signatures of the target // i.e. declare function f(a: 'A'); // f("/*completion position*/") - return argumentInfo && getStringLiteralCompletionsFromSignature(argumentInfo.invocation, node, argumentInfo, typeChecker) || fromContextualType(); + return argumentInfo && getStringLiteralCompletionsFromSignature(argumentInfo.invocation, node, argumentInfo, typeChecker) || fromContextualType(ContextFlags.None); } // falls through (is `require("")` or `require(""` or `import("")`) diff --git a/tests/cases/fourslash/completionsLiteralDirectlyInRestConstrainedToArrayType.ts b/tests/cases/fourslash/completionsLiteralDirectlyInRestConstrainedToArrayType.ts new file mode 100644 index 00000000000..620e4fda5f2 --- /dev/null +++ b/tests/cases/fourslash/completionsLiteralDirectlyInRestConstrainedToArrayType.ts @@ -0,0 +1,9 @@ +/// +// @strict: true +//// +//// function fn(...values: T): T { return values; } +//// +//// const value1 = fn('/*1*/'); +//// const value2 = fn('value1', '/*2*/'); + +verify.completions({ marker: ["1", "2"], includes: [`value1`, `value2`, `value3`] })