From b7b43fe601babb77e55d5b6b0d94231e39ed0f12 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 7 Dec 2017 12:16:29 -0800 Subject: [PATCH] Fixes #20527 --- src/services/codefixes/inferFromUsage.ts | 4 ++++ tests/cases/fourslash/incompleteFunctionCallCodefix3.ts | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/cases/fourslash/incompleteFunctionCallCodefix3.ts diff --git a/src/services/codefixes/inferFromUsage.ts b/src/services/codefixes/inferFromUsage.ts index 25236318612..992770dbd01 100644 --- a/src/services/codefixes/inferFromUsage.ts +++ b/src/services/codefixes/inferFromUsage.ts @@ -71,6 +71,10 @@ namespace ts.codefix { } const containingFunction = getContainingFunction(token); + if (containingFunction === undefined) { + // Possible in certain syntax error cases + return undefined; + } switch (errorCode) { // Variable and Property declarations case Diagnostics.Member_0_implicitly_has_an_1_type.code: diff --git a/tests/cases/fourslash/incompleteFunctionCallCodefix3.ts b/tests/cases/fourslash/incompleteFunctionCallCodefix3.ts new file mode 100644 index 00000000000..3c0261e48a7 --- /dev/null +++ b/tests/cases/fourslash/incompleteFunctionCallCodefix3.ts @@ -0,0 +1,7 @@ +/// + +// @noImplicitAny: true +//// function ...q) {}} f(10); + +verify.not.codeFixAvailable([]); +