From 8e1e8b2c1863d8070c7768002cc9163bb0804ef6 Mon Sep 17 00:00:00 2001 From: hanseul37 Date: Sat, 6 Sep 2025 06:38:47 +0900 Subject: [PATCH 1/2] fix(deprecation): report method name instead of type for deprecated methods (#62396) --- src/compiler/checker.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 66742c94f057e..511608b34fa45 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2611,10 +2611,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return addDeprecatedSuggestionWorker(declarations, diagnostic); } - 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) - : createDiagnosticForNode(location, Diagnostics._0_is_deprecated, signatureString); + function addDeprecatedSuggestionWithSignature(location: Node, declaration: Node, deprecatedEntity: string) { + const diagnostic = createDiagnosticForNode(location, Diagnostics._0_is_deprecated, deprecatedEntity); return addDeprecatedSuggestionWorker(declaration, diagnostic); } @@ -37782,8 +37780,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (signature.flags & SignatureFlags.IsSignatureCandidateForOverloadFailure) return; if (signature.declaration && signature.declaration.flags & NodeFlags.Deprecated) { const suggestionNode = getDeprecatedSuggestionNode(node); - const name = tryGetPropertyAccessOrIdentifierToString(getInvokedExpression(node)); - addDeprecatedSuggestionWithSignature(suggestionNode, signature.declaration, name, signatureToString(signature)); + const invoked = getInvokedExpression(node); + let name = tryGetPropertyAccessOrIdentifierToString(invoked); + + if (!name && invoked.kind === SyntaxKind.PropertyAccessExpression) { + const propAccess = invoked as PropertyAccessExpression; + name = (propAccess.name as any).getText() + "()"; + } + name = name ?? ""; + + addDeprecatedSuggestionWithSignature(suggestionNode, signature.declaration, name); } } From f769c118f4e54154a72d2ebc7f30d5b371e479c7 Mon Sep 17 00:00:00 2001 From: hanseul37 Date: Tue, 9 Sep 2025 01:10:43 +0900 Subject: [PATCH 2/2] fix(deprecation): show method name instead of type in deprecated messages --- src/compiler/checker.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 511608b34fa45..71f2c5bc28180 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2611,8 +2611,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return addDeprecatedSuggestionWorker(declarations, diagnostic); } - function addDeprecatedSuggestionWithSignature(location: Node, declaration: Node, deprecatedEntity: string) { - const diagnostic = createDiagnosticForNode(location, Diagnostics._0_is_deprecated, deprecatedEntity); + function addDeprecatedSuggestionWithSignature(location: Node, declaration: Node, deprecatedEntity: string | undefined, signatureString: string, invoked?: Expression) { + let nameFromInvoked = ""; + if (invoked && invoked.kind === SyntaxKind.PropertyAccessExpression) { + const propAccess = invoked as PropertyAccessExpression; + nameFromInvoked = (propAccess.name as any).getText() + "()"; + } + const diagnostic = deprecatedEntity + ? createDiagnosticForNode(location, Diagnostics.The_signature_0_of_1_is_deprecated, signatureString, deprecatedEntity) + : createDiagnosticForNode(location, Diagnostics._0_is_deprecated, nameFromInvoked); return addDeprecatedSuggestionWorker(declaration, diagnostic); } @@ -37781,15 +37788,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (signature.declaration && signature.declaration.flags & NodeFlags.Deprecated) { const suggestionNode = getDeprecatedSuggestionNode(node); const invoked = getInvokedExpression(node); - let name = tryGetPropertyAccessOrIdentifierToString(invoked); - - if (!name && invoked.kind === SyntaxKind.PropertyAccessExpression) { - const propAccess = invoked as PropertyAccessExpression; - name = (propAccess.name as any).getText() + "()"; - } - name = name ?? ""; - - addDeprecatedSuggestionWithSignature(suggestionNode, signature.declaration, name); + const invokedExpr = invoked && + invoked.kind !== SyntaxKind.JsxElement && + invoked.kind !== SyntaxKind.JsxSelfClosingElement + ? (invoked as Expression) + : undefined; + const name = tryGetPropertyAccessOrIdentifierToString(invoked); + addDeprecatedSuggestionWithSignature(suggestionNode, signature.declaration, name, signatureToString(signature), invokedExpr); } }