Skip to content

Commit a3a076d

Browse files
committed
Did you forget to use await? for call and construct signatures
1 parent 48fc6b8 commit a3a076d

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22342,6 +22342,8 @@ namespace ts {
2234222342
function invocationErrorDetails(apparentType: Type, kind: SignatureKind): DiagnosticMessageChain {
2234322343
let errorInfo: DiagnosticMessageChain | undefined;
2234422344
const isCall = kind === SignatureKind.Call;
22345+
const awaitedType = getAwaitedType(apparentType);
22346+
const mightWorkWithAwait = awaitedType && getSignaturesOfType(awaitedType, kind).length > 0;
2234522347
if (apparentType.flags & TypeFlags.Union) {
2234622348
const types = (apparentType as UnionType).types;
2234722349
let hasSignatures = false;
@@ -22408,9 +22410,9 @@ namespace ts {
2240822410
}
2240922411
return chainDiagnosticMessages(
2241022412
errorInfo,
22411-
isCall ?
22412-
Diagnostics.This_expression_is_not_callable :
22413-
Diagnostics.This_expression_is_not_constructable
22413+
mightWorkWithAwait
22414+
? 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
22415+
: isCall ? Diagnostics.This_expression_is_not_callable : Diagnostics.This_expression_is_not_constructable
2241422416
);
2241522417
}
2241622418
function invocationError(errorTarget: Node, apparentType: Type, kind: SignatureKind, relatedInformation?: DiagnosticRelatedInformation) {

src/compiler/diagnosticMessages.json

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,49 +2705,57 @@
27052705
"category": "Error",
27062706
"code": 2775
27072707
},
2708-
"The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. Did you forget to use 'await'?": {
2708+
"This expression is not callable. Did you forget to use 'await'?": {
2709+
"category": "Error",
2710+
"code": 2776
2711+
},
2712+
"This expression is not constructable. Did you forget to use 'await'?": {
27092713
"category": "Error",
27102714
"code": 2777
27112715
},
2716+
"The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. Did you forget to use 'await'?": {
2717+
"category": "Error",
2718+
"code": 2778
2719+
},
27122720
"Type '{0}' must have a '[Symbol.iterator]()' method that returns an iterator. Did you forget to use 'await'?": {
27132721
"category": "Error",
2714-
"code": 2777
2722+
"code": 2779
27152723
},
27162724
"Type '{0}' must have a '[Symbol.asyncIterator]()' method that returns an async iterator. Did you forget to use 'await'?": {
27172725
"category": "Error",
2718-
"code": 2778
2726+
"code": 2780
27192727
},
27202728
"Type '{0}' is not an array type. Did you forget to use 'await'?": {
27212729
"category": "Error",
2722-
"code": 2779
2730+
"code": 2781
27232731
},
27242732
"Type '{0}' is not an array type or a string type. Did you forget to use 'await'?": {
27252733
"category": "Error",
2726-
"code": 2780
2734+
"code": 2782
27272735
},
27282736
"Type '{0}' is not an array type or does not have a '[Symbol.iterator]()' method that returns an iterator. Did you forget to use 'await'?": {
27292737
"category": "Error",
2730-
"code": 2781
2738+
"code": 2783
27312739
},
27322740
"Type '{0}' is not an array type or a string type or does not have a '[Symbol.iterator]()' method that returns an iterator. Did you forget to use 'await'?": {
27332741
"category": "Error",
2734-
"code": 2782
2742+
"code": 2784
27352743
},
27362744
"Argument of type '{0}' is not assignable to parameter of type '{1}'. Did you forget to use 'await'?": {
27372745
"category": "Error",
2738-
"code": 2783
2746+
"code": 2785
27392747
},
27402748
"Type '{0}' has no call signatures. Did you forget to use 'await'?": {
27412749
"category": "Error",
2742-
"code": 2784
2750+
"code": 2786
27432751
},
27442752
"Type '{0}' has no construct signatures. Did you forget to use 'await'?": {
27452753
"category": "Error",
2746-
"code": 2785
2754+
"code": 2787
27472755
},
27482756
"This condition will always return '{0}' since the types '{1}' and '{2}' have no overlap. Did you forget to use 'await'?": {
27492757
"category": "Error",
2750-
"code": 2786
2758+
"code": 2788
27512759
},
27522760

27532761
"Import declaration '{0}' is using private name '{1}'.": {

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)