From 5cb6a24365cd33be5fe2962e486b7c9104a5339a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 22 Apr 2022 14:16:05 +0200 Subject: [PATCH] Fixed string literal completions for partially-typed strings when overload could get matched --- src/compiler/checker.ts | 3 ++- .../completionsLiteralMatchingGenericSignature.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionsLiteralMatchingGenericSignature.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5748f07630582..477851cc4e299 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -30501,6 +30501,7 @@ namespace ts { // decorators are applied to a declaration by the emitter, and not to an expression. const isSingleNonGenericCandidate = candidates.length === 1 && !candidates[0].typeParameters; let argCheckMode = !isDecorator && !isSingleNonGenericCandidate && some(args, isContextSensitive) ? CheckMode.SkipContextSensitive : CheckMode.Normal; + argCheckMode |= checkMode & CheckMode.IsForStringLiteralArgumentCompletions; // The following variables are captured and modified by calls to chooseOverload. // If overload resolution or type argument inference fails, we want to report the @@ -30726,7 +30727,7 @@ namespace ts { // If one or more context sensitive arguments were excluded, we start including // them now (and keeping do so for any subsequent candidates) and perform a second // round of type inference and applicability checking for this particular candidate. - argCheckMode = CheckMode.Normal; + argCheckMode = checkMode & CheckMode.IsForStringLiteralArgumentCompletions; if (inferenceContext) { const typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode, inferenceContext); checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters); diff --git a/tests/cases/fourslash/completionsLiteralMatchingGenericSignature.ts b/tests/cases/fourslash/completionsLiteralMatchingGenericSignature.ts new file mode 100644 index 0000000000000..85e44adf14a74 --- /dev/null +++ b/tests/cases/fourslash/completionsLiteralMatchingGenericSignature.ts @@ -0,0 +1,9 @@ +/// + +// @Filename: /a.tsx +//// declare function bar1

(p: P): void; +//// +//// bar1("/*ts*/") +//// + +verify.completions({ marker: ["ts"], exact: ["", "bar", "baz"] });