diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go index 983fc751b03f8..19b4ac83d6196 100644 --- a/tsc/internal/checker/checker.go +++ b/tsc/internal/checker/checker.go @@ -8539,7 +8539,18 @@ func (c *Checker) checkDeprecatedSignature(sig *Signature, node *ast.Node) { } if sig.declaration != nil && c.IsDeprecatedDeclaration(sig.declaration) { suggestionNode := c.getDeprecatedSuggestionNode(node) - name := tryGetPropertyAccessOrIdentifierToString(ast.GetInvokedExpression(node)) + invokedExpression := ast.SkipParentheses(ast.GetInvokedExpression(node)) + name := tryGetPropertyAccessOrIdentifierToString(invokedExpression) + if name == "" { + switch { + case ast.IsPropertyAccessExpression(invokedExpression): + name = invokedExpression.Name().Text() + case ast.IsElementAccessExpression(invokedExpression): + if memberName := ast.GetElementOrPropertyAccessName(invokedExpression); memberName != nil { + name = memberName.Text() + } + } + } c.addDeprecatedSuggestionWithSignature(suggestionNode, sig.declaration, name, c.signatureToString(sig)) } } diff --git a/tsc/internal/fourslash/tests/deprecatedSignatureMemberName_test.go b/tsc/internal/fourslash/tests/deprecatedSignatureMemberName_test.go new file mode 100644 index 0000000000000..c456a9b777ef5 --- /dev/null +++ b/tsc/internal/fourslash/tests/deprecatedSignatureMemberName_test.go @@ -0,0 +1,74 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/TypeScript/tsc/internal/fourslash" + "github.com/microsoft/TypeScript/tsc/internal/lsp/lsproto" + "github.com/microsoft/TypeScript/tsc/internal/testutil" +) + +func TestDeprecatedSignatureMemberName(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @filename: /a.ts +interface Schema { + /** @deprecated */ + passthrough(): Schema; +} +declare function object(): Schema; +object().[|passthrough|](); +object()[[|"passthrough"|]](); +(object().[|passthrough|])(); +class C { + /** @deprecated */ + m() {} + /** @deprecated */ + #p() {} + n() { + this.[|m|](); + this.[|#p|](); + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifySuggestionDiagnostics(t, []*lsproto.Diagnostic{ + { + Code: &lsproto.IntegerOrString{Integer: new(int32(6387))}, + Message: lsproto.StringOrMarkupContent{String: new("The signature '(): Schema' of 'passthrough' is deprecated.")}, + Tags: &[]lsproto.DiagnosticTag{lsproto.DiagnosticTagDeprecated}, + Range: f.Ranges()[0].LSRange, + }, + { + Code: &lsproto.IntegerOrString{Integer: new(int32(6387))}, + Message: lsproto.StringOrMarkupContent{String: new("The signature '(): Schema' of 'passthrough' is deprecated.")}, + Tags: &[]lsproto.DiagnosticTag{lsproto.DiagnosticTagDeprecated}, + Range: f.Ranges()[1].LSRange, + }, + // A parenthesized callee also reports the deprecated property itself; that suggestion is unchanged. + { + Code: &lsproto.IntegerOrString{Integer: new(int32(6385))}, + Message: lsproto.StringOrMarkupContent{String: new("'passthrough' is deprecated.")}, + Tags: &[]lsproto.DiagnosticTag{lsproto.DiagnosticTagDeprecated}, + Range: f.Ranges()[2].LSRange, + }, + { + Code: &lsproto.IntegerOrString{Integer: new(int32(6387))}, + Message: lsproto.StringOrMarkupContent{String: new("The signature '(): Schema' of 'passthrough' is deprecated.")}, + Tags: &[]lsproto.DiagnosticTag{lsproto.DiagnosticTagDeprecated}, + Range: f.Ranges()[2].LSRange, + }, + { + Code: &lsproto.IntegerOrString{Integer: new(int32(6387))}, + Message: lsproto.StringOrMarkupContent{String: new("The signature '(): void' of 'm' is deprecated.")}, + Tags: &[]lsproto.DiagnosticTag{lsproto.DiagnosticTagDeprecated}, + Range: f.Ranges()[3].LSRange, + }, + { + Code: &lsproto.IntegerOrString{Integer: new(int32(6387))}, + Message: lsproto.StringOrMarkupContent{String: new("The signature '(): void' of '#p' is deprecated.")}, + Tags: &[]lsproto.DiagnosticTag{lsproto.DiagnosticTagDeprecated}, + Range: f.Ranges()[4].LSRange, + }, + }) +}