From 24b39f90c92befca6b8732704dd8e360a513d469 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 4 Dec 2018 09:17:37 -0800 Subject: [PATCH] Skip implicit any suggestions with no codefix (#28822) The only unsupported one is binding patterns, which aren't supported by the codefix. The code was a lot faster to write without supporting them, but there's no real barrier besides that. --- src/compiler/checker.ts | 4 ++++ .../fourslash/codeFixInferFromUsageBindingElement.ts | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 tests/cases/fourslash/codeFixInferFromUsageBindingElement.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e1aad0b3835..f9affcad6bc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13684,6 +13684,10 @@ namespace ts { break; case SyntaxKind.BindingElement: diagnostic = Diagnostics.Binding_element_0_implicitly_has_an_1_type; + if (!noImplicitAny) { + // Don't issue a suggestion for binding elements since the codefix doesn't yet support them. + return; + } break; case SyntaxKind.JSDocFunctionType: error(declaration, Diagnostics.Function_type_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString); diff --git a/tests/cases/fourslash/codeFixInferFromUsageBindingElement.ts b/tests/cases/fourslash/codeFixInferFromUsageBindingElement.ts new file mode 100644 index 00000000000..e60b7efa3b9 --- /dev/null +++ b/tests/cases/fourslash/codeFixInferFromUsageBindingElement.ts @@ -0,0 +1,8 @@ +/// +////function f([car, cdr]) { +//// return car + cdr + 1 +////} + +// When inferFromUsage supports it, it should infer number for both variables +verify.getSuggestionDiagnostics([]); +