From 91f7cfc50101bdbbfcc068a6f56f642c8528129c Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 19 Jul 2022 00:49:13 +0300 Subject: [PATCH] fix(49392): show optional class methods with enabled strict option (#49768) --- src/services/codefixes/helpers.ts | 2 +- .../completionsOverridingMethod14.ts | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionsOverridingMethod14.ts diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index 94b64e57ac9..edcfe0a960c 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -138,7 +138,7 @@ namespace ts.codefix { // If there is more than one overload but no implementation signature // (eg: an abstract method or interface declaration), there is a 1-1 // correspondence of declarations and signatures. - const signatures = checker.getSignaturesOfType(type, SignatureKind.Call); + const signatures = type.isUnion() ? flatMap(type.types, t => t.getCallSignatures()) : type.getCallSignatures(); if (!some(signatures)) { break; } diff --git a/tests/cases/fourslash/completionsOverridingMethod14.ts b/tests/cases/fourslash/completionsOverridingMethod14.ts new file mode 100644 index 00000000000..37aeae70790 --- /dev/null +++ b/tests/cases/fourslash/completionsOverridingMethod14.ts @@ -0,0 +1,29 @@ +/// + +// @Filename: a.ts +// @strictNullChecks: true +// @newline: LF + +////interface IFoo { +//// foo?(arg: string): number; +////} +////class Foo implements IFoo { +//// /**/ +////} + +verify.completions({ + marker: "", + isNewIdentifierLocation: true, + preferences: { + includeCompletionsWithInsertText: true, + includeCompletionsWithSnippetText: false, + includeCompletionsWithClassMemberSnippets: true, + }, + includes: [ + { + name: "foo", + sortText: completion.SortText.ClassMemberSnippets, + insertText: "foo(arg: string): number {\n}" + }, + ], +});