From 8e1f8b6c7a11cec03382bc0732114747a3a843d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 9 Jun 2023 19:10:46 +0200 Subject: [PATCH] Fixed a regression with string completions not being available directly in arguments typed using rest parameter --- 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 df0e24e558983..150d0652dd28c 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 0000000000000..620e4fda5f24d --- /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`] })