Skip to content

Commit 1cb015f

Browse files
committed
Did you forget to use await? for call and construct signatures
1 parent a32bd7d commit 1cb015f

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22058,6 +22058,8 @@ namespace ts {
2205822058
function invocationErrorDetails(apparentType: Type, kind: SignatureKind): DiagnosticMessageChain {
2205922059
let errorInfo: DiagnosticMessageChain | undefined;
2206022060
const isCall = kind === SignatureKind.Call;
22061+
const awaitedType = getAwaitedType(apparentType);
22062+
const mightWorkWithAwait = awaitedType && getSignaturesOfType(awaitedType, kind).length > 0;
2206122063
if (apparentType.flags & TypeFlags.Union) {
2206222064
const types = (apparentType as UnionType).types;
2206322065
let hasSignatures = false;
@@ -22124,9 +22126,9 @@ namespace ts {
2212422126
}
2212522127
return chainDiagnosticMessages(
2212622128
errorInfo,
22127-
isCall ?
22128-
Diagnostics.This_expression_is_not_callable :
22129-
Diagnostics.This_expression_is_not_constructable
22129+
mightWorkWithAwait
22130+
? isCall ? Diagnostics.This_expression_is_not_callable_Did_you_forget_to_use_await : Diagnostics.This_expression_is_not_constructable_Did_you_forget_to_use_await
22131+
: isCall ? Diagnostics.This_expression_is_not_callable : Diagnostics.This_expression_is_not_constructable
2213022132
);
2213122133
}
2213222134
function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) {

src/compiler/diagnosticMessages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,11 +2697,11 @@
26972697
"category": "Error",
26982698
"code": 2773
26992699
},
2700-
"Type '{0}' has no call signatures. Did you forget to use 'await'?": {
2700+
"This expression is not callable. Did you forget to use 'await'?": {
27012701
"category": "Error",
27022702
"code": 2774
27032703
},
2704-
"Type '{0}' has no construct signatures. Did you forget to use 'await'?": {
2704+
"This expression is not constructable. Did you forget to use 'await'?": {
27052705
"category": "Error",
27062706
"code": 2775
27072707
},

tests/cases/compiler/operationsAvailableOnPromisedType.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ async function fn(
2424
e();
2525
f();
2626
new g();
27+
b();
2728
}

0 commit comments

Comments
 (0)