Skip to content

Commit 8e1e8b2

Browse files
committed
fix(deprecation): report method name instead of type for deprecated methods (#62396)
1 parent 7956c00 commit 8e1e8b2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,10 +2611,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
26112611
return addDeprecatedSuggestionWorker(declarations, diagnostic);
26122612
}
26132613

2614-
function addDeprecatedSuggestionWithSignature(location: Node, declaration: Node, deprecatedEntity: string | undefined, signatureString: string) {
2615-
const diagnostic = deprecatedEntity
2616-
? createDiagnosticForNode(location, Diagnostics.The_signature_0_of_1_is_deprecated, signatureString, deprecatedEntity)
2617-
: createDiagnosticForNode(location, Diagnostics._0_is_deprecated, signatureString);
2614+
function addDeprecatedSuggestionWithSignature(location: Node, declaration: Node, deprecatedEntity: string) {
2615+
const diagnostic = createDiagnosticForNode(location, Diagnostics._0_is_deprecated, deprecatedEntity);
26182616
return addDeprecatedSuggestionWorker(declaration, diagnostic);
26192617
}
26202618

@@ -37782,8 +37780,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3778237780
if (signature.flags & SignatureFlags.IsSignatureCandidateForOverloadFailure) return;
3778337781
if (signature.declaration && signature.declaration.flags & NodeFlags.Deprecated) {
3778437782
const suggestionNode = getDeprecatedSuggestionNode(node);
37785-
const name = tryGetPropertyAccessOrIdentifierToString(getInvokedExpression(node));
37786-
addDeprecatedSuggestionWithSignature(suggestionNode, signature.declaration, name, signatureToString(signature));
37783+
const invoked = getInvokedExpression(node);
37784+
let name = tryGetPropertyAccessOrIdentifierToString(invoked);
37785+
37786+
if (!name && invoked.kind === SyntaxKind.PropertyAccessExpression) {
37787+
const propAccess = invoked as PropertyAccessExpression;
37788+
name = (propAccess.name as any).getText() + "()";
37789+
}
37790+
name = name ?? "<unknown>";
37791+
37792+
addDeprecatedSuggestionWithSignature(suggestionNode, signature.declaration, name);
3778737793
}
3778837794
}
3778937795

0 commit comments

Comments
 (0)