diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 66742c94f057e..71f2c5bc28180 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2611,10 +2611,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return addDeprecatedSuggestionWorker(declarations, diagnostic); } - function addDeprecatedSuggestionWithSignature(location: Node, declaration: Node, deprecatedEntity: string | undefined, signatureString: string) { + 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, signatureString); + : createDiagnosticForNode(location, Diagnostics._0_is_deprecated, nameFromInvoked); return addDeprecatedSuggestionWorker(declaration, diagnostic); } @@ -37782,8 +37787,14 @@ 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); + 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); } }