@@ -26049,7 +26049,7 @@ namespace ts {
26049
26049
return true;
26050
26050
}
26051
26051
26052
- function invocationErrorDetails(apparentType: Type, kind: SignatureKind): { messageChain: DiagnosticMessageChain, relatedMessage: DiagnosticMessage | undefined } {
26052
+ function invocationErrorDetails(errorTarget: Node, apparentType: Type, kind: SignatureKind): { messageChain: DiagnosticMessageChain, relatedMessage: DiagnosticMessage | undefined } {
26053
26053
let errorInfo: DiagnosticMessageChain | undefined;
26054
26054
const isCall = kind === SignatureKind.Call;
26055
26055
const awaitedType = getAwaitedType(apparentType);
@@ -26118,6 +26118,15 @@ namespace ts {
26118
26118
typeToString(apparentType)
26119
26119
);
26120
26120
}
26121
+
26122
+ // Diagnose get accessors incorrectly called as functions
26123
+ if (isCallExpression(errorTarget.parent) && errorTarget.parent.arguments.length === 0) {
26124
+ const { resolvedSymbol } = getNodeLinks(errorTarget);
26125
+ if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) {
26126
+ errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without);
26127
+ }
26128
+ }
26129
+
26121
26130
return {
26122
26131
messageChain: chainDiagnosticMessages(
26123
26132
errorInfo,
@@ -26127,21 +26136,10 @@ namespace ts {
26127
26136
};
26128
26137
}
26129
26138
function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) {
26130
- let diagnostic;
26131
- if (isCallExpression(errorTarget.parent) && errorTarget.parent.arguments.length === 0) {
26132
- // Diagnose get accessors incorrectly called as functions
26133
- const { resolvedSymbol } = getNodeLinks(errorTarget);
26134
- if (resolvedSymbol && resolvedSymbol.flags & SymbolFlags.GetAccessor) {
26135
- diagnostic = createDiagnosticForNode(errorTarget, Diagnostics.This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without);
26136
- addRelatedInfo(diagnostic, createDiagnosticForNode(resolvedSymbol.valueDeclaration, Diagnostics._0_is_declared_here, symbolToString(resolvedSymbol)));
26137
- }
26138
- }
26139
- if (!diagnostic) {
26140
- const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(apparentType, kind);
26141
- diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain);
26142
- if (relatedInfo) {
26143
- addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
26144
- }
26139
+ const { messageChain, relatedMessage: relatedInfo } = invocationErrorDetails(errorTarget, apparentType, kind);
26140
+ const diagnostic = createDiagnosticForNodeFromMessageChain(errorTarget, messageChain);
26141
+ if (relatedInfo) {
26142
+ addRelatedInfo(diagnostic, createDiagnosticForNode(errorTarget, relatedInfo));
26145
26143
}
26146
26144
if (isCallExpression(errorTarget.parent)) {
26147
26145
const { start, length } = getDiagnosticSpanForCallNode(errorTarget.parent, /* doNotIncludeArguments */ true);
@@ -26242,7 +26240,7 @@ namespace ts {
26242
26240
26243
26241
const headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
26244
26242
if (!callSignatures.length) {
26245
- const errorDetails = invocationErrorDetails(apparentType, SignatureKind.Call);
26243
+ const errorDetails = invocationErrorDetails(node.expression, apparentType, SignatureKind.Call);
26246
26244
const messageChain = chainDiagnosticMessages(errorDetails.messageChain, headMessage);
26247
26245
const diag = createDiagnosticForNodeFromMessageChain(node.expression, messageChain);
26248
26246
if (errorDetails.relatedMessage) {
0 commit comments