From 6e74f7ee11ae47fb2481dd07b998bc523aec75a5 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 6 Dec 2017 15:58:50 -0800 Subject: [PATCH] Fix #20523 --- src/services/codefixes/inferFromUsage.ts | 5 +++++ tests/cases/fourslash/incompleteFunctionCallCodefix.ts | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 tests/cases/fourslash/incompleteFunctionCallCodefix.ts diff --git a/src/services/codefixes/inferFromUsage.ts b/src/services/codefixes/inferFromUsage.ts index 9782619d41d..d7bfd1b621f 100644 --- a/src/services/codefixes/inferFromUsage.ts +++ b/src/services/codefixes/inferFromUsage.ts @@ -148,6 +148,11 @@ namespace ts.codefix { containingFunction.parameters.map(p => isIdentifier(p.name) ? inferTypeForVariableFromUsage(p.name, sourceFile, program, cancellationToken) : undefined); if (!types) return undefined; + // We didn't actually find a set of type inference positions matching each parameter position + if (containingFunction.parameters.length !== types.length) { + return undefined; + } + const textChanges = arrayFrom(mapDefinedIterator(zipToIterator(containingFunction.parameters, types), ([parameter, type]) => type && !parameter.type && !parameter.initializer ? makeChange(containingFunction, parameter.end, type, program) : undefined)); return textChanges.length ? { declaration: parameterDeclaration, textChanges } : undefined; diff --git a/tests/cases/fourslash/incompleteFunctionCallCodefix.ts b/tests/cases/fourslash/incompleteFunctionCallCodefix.ts new file mode 100644 index 00000000000..007eaa20f7f --- /dev/null +++ b/tests/cases/fourslash/incompleteFunctionCallCodefix.ts @@ -0,0 +1,9 @@ +/// + +// @noImplicitAny: true +//// function f(/*1*/x) { +//// } +//// f( + +verify.not.codeFixAvailable([]); +