From 1387e08e042a4e4a7360b88ecd4e5422e660426e Mon Sep 17 00:00:00 2001 From: Arnav Nagzirkar <113314200+arnavnagzirkar@users.noreply.github.com> Date: Sun, 31 May 2026 20:05:21 -0700 Subject: [PATCH] fix: Deprecation error message reporting method type as deprecated instead of Fixes microsoft/TypeScript#62396 --- src/compiler/checker.ts | 2 + .../deprecatedMethodOnChainedCall.errors.txt | 22 +++++++++ .../deprecatedMethodOnChainedCall.symbols | 32 +++++++++++++ .../deprecatedMethodOnChainedCall.types | 45 +++++++++++++++++++ .../compiler/deprecatedMethodOnChainedCall.ts | 17 +++++++ 5 files changed, 118 insertions(+) create mode 100644 tests/baselines/reference/deprecatedMethodOnChainedCall.errors.txt create mode 100644 tests/baselines/reference/deprecatedMethodOnChainedCall.symbols create mode 100644 tests/baselines/reference/deprecatedMethodOnChainedCall.types create mode 100644 tests/cases/compiler/deprecatedMethodOnChainedCall.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0567712f11da3..cd1c420963cd8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2626,6 +2626,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function addDeprecatedSuggestionWithSignature(location: Node, declaration: Node, deprecatedEntity: string | undefined, signatureString: string) { const diagnostic = deprecatedEntity ? createDiagnosticForNode(location, Diagnostics.The_signature_0_of_1_is_deprecated, signatureString, deprecatedEntity) + : isIdentifier(location) + ? createDiagnosticForNode(location, Diagnostics._0_is_deprecated, idText(location)) : createDiagnosticForNode(location, Diagnostics._0_is_deprecated, signatureString); return addDeprecatedSuggestionWorker(declaration, diagnostic); } diff --git a/tests/baselines/reference/deprecatedMethodOnChainedCall.errors.txt b/tests/baselines/reference/deprecatedMethodOnChainedCall.errors.txt new file mode 100644 index 0000000000000..ba7d77e9125a7 --- /dev/null +++ b/tests/baselines/reference/deprecatedMethodOnChainedCall.errors.txt @@ -0,0 +1,22 @@ +deprecatedMethodOnChainedCall.ts(14,32): suggestion TS6385: 'oldMethod' is deprecated. + + +==== deprecatedMethodOnChainedCall.ts (1 errors) ==== + // Regression test for https://github.com/microsoft/TypeScript/issues/62396 + // Deprecation message should show the method name, not the type signature + + interface Builder { + configure(value: string): Builder; + /** @deprecated use {@link Builder} instead */ + oldMethod(): void; + } + + declare function createBuilder(): Builder; + + // When calling a deprecated method on the result of another call (chained call), + // the deprecation message should show the method name, not the type signature. + createBuilder().configure("x").oldMethod(); + ~~~~~~~~~ +!!! suggestion TS6385: 'oldMethod' is deprecated. +!!! related TS2798 deprecatedMethodOnChainedCall.ts:6:9: The declaration was marked as deprecated here. + \ No newline at end of file diff --git a/tests/baselines/reference/deprecatedMethodOnChainedCall.symbols b/tests/baselines/reference/deprecatedMethodOnChainedCall.symbols new file mode 100644 index 0000000000000..94a824d1cd5f9 --- /dev/null +++ b/tests/baselines/reference/deprecatedMethodOnChainedCall.symbols @@ -0,0 +1,32 @@ +//// [tests/cases/compiler/deprecatedMethodOnChainedCall.ts] //// + +=== deprecatedMethodOnChainedCall.ts === +// Regression test for https://github.com/microsoft/TypeScript/issues/62396 +// Deprecation message should show the method name, not the type signature + +interface Builder { +>Builder : Symbol(Builder, Decl(deprecatedMethodOnChainedCall.ts, 0, 0)) + + configure(value: string): Builder; +>configure : Symbol(Builder.configure, Decl(deprecatedMethodOnChainedCall.ts, 3, 19)) +>value : Symbol(value, Decl(deprecatedMethodOnChainedCall.ts, 4, 14)) +>Builder : Symbol(Builder, Decl(deprecatedMethodOnChainedCall.ts, 0, 0)) + + /** @deprecated use {@link Builder} instead */ + oldMethod(): void; +>oldMethod : Symbol(Builder.oldMethod, Decl(deprecatedMethodOnChainedCall.ts, 4, 38)) +} + +declare function createBuilder(): Builder; +>createBuilder : Symbol(createBuilder, Decl(deprecatedMethodOnChainedCall.ts, 7, 1)) +>Builder : Symbol(Builder, Decl(deprecatedMethodOnChainedCall.ts, 0, 0)) + +// When calling a deprecated method on the result of another call (chained call), +// the deprecation message should show the method name, not the type signature. +createBuilder().configure("x").oldMethod(); +>createBuilder().configure("x").oldMethod : Symbol(Builder.oldMethod, Decl(deprecatedMethodOnChainedCall.ts, 4, 38)) +>createBuilder().configure : Symbol(Builder.configure, Decl(deprecatedMethodOnChainedCall.ts, 3, 19)) +>createBuilder : Symbol(createBuilder, Decl(deprecatedMethodOnChainedCall.ts, 7, 1)) +>configure : Symbol(Builder.configure, Decl(deprecatedMethodOnChainedCall.ts, 3, 19)) +>oldMethod : Symbol(Builder.oldMethod, Decl(deprecatedMethodOnChainedCall.ts, 4, 38)) + diff --git a/tests/baselines/reference/deprecatedMethodOnChainedCall.types b/tests/baselines/reference/deprecatedMethodOnChainedCall.types new file mode 100644 index 0000000000000..9ad47ebe0a3ae --- /dev/null +++ b/tests/baselines/reference/deprecatedMethodOnChainedCall.types @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/deprecatedMethodOnChainedCall.ts] //// + +=== deprecatedMethodOnChainedCall.ts === +// Regression test for https://github.com/microsoft/TypeScript/issues/62396 +// Deprecation message should show the method name, not the type signature + +interface Builder { + configure(value: string): Builder; +>configure : (value: string) => Builder +> : ^ ^^ ^^^^^ +>value : string +> : ^^^^^^ + + /** @deprecated use {@link Builder} instead */ + oldMethod(): void; +>oldMethod : () => void +> : ^^^^^^ +} + +declare function createBuilder(): Builder; +>createBuilder : () => Builder +> : ^^^^^^ + +// When calling a deprecated method on the result of another call (chained call), +// the deprecation message should show the method name, not the type signature. +createBuilder().configure("x").oldMethod(); +>createBuilder().configure("x").oldMethod() : void +> : ^^^^ +>createBuilder().configure("x").oldMethod : () => void +> : ^^^^^^ +>createBuilder().configure("x") : Builder +> : ^^^^^^^ +>createBuilder().configure : (value: string) => Builder +> : ^ ^^ ^^^^^ +>createBuilder() : Builder +> : ^^^^^^^ +>createBuilder : () => Builder +> : ^^^^^^ +>configure : (value: string) => Builder +> : ^ ^^ ^^^^^ +>"x" : "x" +> : ^^^ +>oldMethod : () => void +> : ^^^^^^ + diff --git a/tests/cases/compiler/deprecatedMethodOnChainedCall.ts b/tests/cases/compiler/deprecatedMethodOnChainedCall.ts new file mode 100644 index 0000000000000..038ca5eeeec6b --- /dev/null +++ b/tests/cases/compiler/deprecatedMethodOnChainedCall.ts @@ -0,0 +1,17 @@ +// @noEmit: true +// @captureSuggestions: true + +// Regression test for https://github.com/microsoft/TypeScript/issues/62396 +// Deprecation message should show the method name, not the type signature + +interface Builder { + configure(value: string): Builder; + /** @deprecated use {@link Builder} instead */ + oldMethod(): void; +} + +declare function createBuilder(): Builder; + +// When calling a deprecated method on the result of another call (chained call), +// the deprecation message should show the method name, not the type signature. +createBuilder().configure("x").oldMethod();