Skip to content

Commit 094a001

Browse files
committed
Did you forget to use await? on arguments of function calls
1 parent e89a2c4 commit 094a001

7 files changed

+32
-11
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21434,6 +21434,7 @@ namespace ts {
2143421434
const checkArgType = checkMode & CheckMode.SkipContextSensitive ? getRegularTypeOfObjectLiteral(argType) : argType;
2143521435
if (!checkTypeRelatedToAndOptionallyElaborate(checkArgType, paramType, relation, reportErrors ? arg : undefined, arg, headMessage, containingMessageChain, errorOutputContainer)) {
2143621436
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "parameter should have errors when reporting errors");
21437+
maybeAddMissingAwaitInfo(arg, checkArgType, paramType);
2143721438
return errorOutputContainer.errors || [];
2143821439
}
2143921440
}
@@ -21443,10 +21444,20 @@ namespace ts {
2144321444
const errorNode = reportErrors ? argCount < args.length ? args[argCount] : node : undefined;
2144421445
if (!checkTypeRelatedTo(spreadType, restType, relation, errorNode, headMessage, /*containingMessageChain*/ undefined, errorOutputContainer)) {
2144521446
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "rest parameter should have errors when reporting errors");
21447+
maybeAddMissingAwaitInfo(errorNode, spreadType, restType);
2144621448
return errorOutputContainer.errors || [];
2144721449
}
2144821450
}
2144921451
return undefined;
21452+
21453+
function maybeAddMissingAwaitInfo(errorNode: Node | undefined, source: Type, target: Type) {
21454+
if (errorNode && reportErrors && errorOutputContainer.errors && errorOutputContainer.errors.length) {
21455+
const awaitedTypeOfSource = getAwaitedTypeOfPromise(source);
21456+
if (awaitedTypeOfSource && isTypeRelatedTo(awaitedTypeOfSource, target, relation)) {
21457+
addRelatedInfo(errorOutputContainer.errors[0], createDiagnosticForNode(errorNode, Diagnostics.Did_you_forget_to_use_await));
21458+
}
21459+
}
21460+
}
2145021461
}
2145121462

2145221463
/**

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,6 +2757,10 @@
27572757
"category": "Error",
27582758
"code": 2788
27592759
},
2760+
"Did you forget to use 'await'?": {
2761+
"category": "Error",
2762+
"code": 2789
2763+
},
27602764

27612765
"Import declaration '{0}' is using private name '{1}'.": {
27622766
"category": "Error",

tests/baselines/reference/operationsAvailableOnPromisedType.errors.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tests/cases/compiler/operationsAvailableOnPromisedType.ts(16,7): error TS2764: A
77
tests/cases/compiler/operationsAvailableOnPromisedType.ts(17,5): error TS2776: This condition will always return 'false' since the types 'number' and 'Promise<number>' have no overlap. Did you forget to use 'await'?
88
tests/cases/compiler/operationsAvailableOnPromisedType.ts(18,9): error TS2769: Type 'Promise<string[]>' is not an array type. Did you forget to use 'await'?
99
tests/cases/compiler/operationsAvailableOnPromisedType.ts(19,21): error TS2770: Type 'Promise<string[]>' is not an array type or a string type. Did you forget to use 'await'?
10-
tests/cases/compiler/operationsAvailableOnPromisedType.ts(20,9): error TS2554: Expected 7 arguments, but got 4.
10+
tests/cases/compiler/operationsAvailableOnPromisedType.ts(20,12): error TS2345: Argument of type 'Promise<number>' is not assignable to parameter of type 'number'.
1111
tests/cases/compiler/operationsAvailableOnPromisedType.ts(21,11): error TS2570: Property 'prop' does not exist on type 'Promise<{ prop: string; }>'. Did you forget to use 'await'?
1212
tests/cases/compiler/operationsAvailableOnPromisedType.ts(23,27): error TS2770: Type 'Promise<string[]>' is not an array type or a string type. Did you forget to use 'await'?
1313
tests/cases/compiler/operationsAvailableOnPromisedType.ts(24,5): error TS2774: This expression is not callable. Did you forget to use 'await'?
@@ -59,10 +59,10 @@ tests/cases/compiler/operationsAvailableOnPromisedType.ts(27,5): error TS2349: T
5959
for (const s of c) {
6060
~
6161
!!! error TS2770: Type 'Promise<string[]>' is not an array type or a string type. Did you forget to use 'await'?
62-
fn(b, b, c, d);
63-
~~~~~~~~~~~~~~
64-
!!! error TS2554: Expected 7 arguments, but got 4.
65-
!!! related TS6210 tests/cases/compiler/operationsAvailableOnPromisedType.ts:6:5: An argument for 'e' was not provided.
62+
fn(b, b, c, d, e, f, g);
63+
~
64+
!!! error TS2345: Argument of type 'Promise<number>' is not assignable to parameter of type 'number'.
65+
!!! related TS2777 tests/cases/compiler/operationsAvailableOnPromisedType.ts:20:12: Did you forget to use 'await'?
6666
d.prop;
6767
~~~~
6868
!!! error TS2570: Property 'prop' does not exist on type 'Promise<{ prop: string; }>'. Did you forget to use 'await'?

tests/baselines/reference/operationsAvailableOnPromisedType.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function fn(
1818
a === b;
1919
[...c];
2020
for (const s of c) {
21-
fn(b, b, c, d);
21+
fn(b, b, c, d, e, f, g);
2222
d.prop;
2323
}
2424
for await (const s of c) {}
@@ -98,7 +98,7 @@ function fn(a, b, c, d, e, f, g) {
9898
__spreadArrays(c);
9999
for (_i = 0, c_2 = c; _i < c_2.length; _i++) {
100100
s = c_2[_i];
101-
fn(b, b, c, d);
101+
fn(b, b, c, d, e, f, g);
102102
d.prop;
103103
}
104104
_b.label = 1;

tests/baselines/reference/operationsAvailableOnPromisedType.symbols

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ async function fn(
6565
>s : Symbol(s, Decl(operationsAvailableOnPromisedType.ts, 18, 14))
6666
>c : Symbol(c, Decl(operationsAvailableOnPromisedType.ts, 2, 23))
6767

68-
fn(b, b, c, d);
68+
fn(b, b, c, d, e, f, g);
6969
>fn : Symbol(fn, Decl(operationsAvailableOnPromisedType.ts, 0, 0))
7070
>b : Symbol(b, Decl(operationsAvailableOnPromisedType.ts, 1, 14))
7171
>b : Symbol(b, Decl(operationsAvailableOnPromisedType.ts, 1, 14))
7272
>c : Symbol(c, Decl(operationsAvailableOnPromisedType.ts, 2, 23))
7373
>d : Symbol(d, Decl(operationsAvailableOnPromisedType.ts, 3, 25))
74+
>e : Symbol(e, Decl(operationsAvailableOnPromisedType.ts, 4, 33))
75+
>f : Symbol(f, Decl(operationsAvailableOnPromisedType.ts, 5, 27))
76+
>g : Symbol(g, Decl(operationsAvailableOnPromisedType.ts, 6, 42))
7477

7578
d.prop;
7679
>d : Symbol(d, Decl(operationsAvailableOnPromisedType.ts, 3, 25))

tests/baselines/reference/operationsAvailableOnPromisedType.types

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@ async function fn(
6868
>s : any
6969
>c : Promise<string[]>
7070

71-
fn(b, b, c, d);
72-
>fn(b, b, c, d) : Promise<void>
71+
fn(b, b, c, d, e, f, g);
72+
>fn(b, b, c, d, e, f, g) : Promise<void>
7373
>fn : (a: number, b: Promise<number>, c: Promise<string[]>, d: Promise<{ prop: string; }>, e: Promise<() => void>, f: Promise<() => void> | (() => void), g: Promise<new () => any>) => Promise<void>
7474
>b : Promise<number>
7575
>b : Promise<number>
7676
>c : Promise<string[]>
7777
>d : Promise<{ prop: string; }>
78+
>e : Promise<() => void>
79+
>f : Promise<() => void> | (() => void)
80+
>g : Promise<new () => any>
7881

7982
d.prop;
8083
>d.prop : any

tests/cases/compiler/operationsAvailableOnPromisedType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function fn(
1717
a === b;
1818
[...c];
1919
for (const s of c) {
20-
fn(b, b, c, d);
20+
fn(b, b, c, d, e, f, g);
2121
d.prop;
2222
}
2323
for await (const s of c) {}

0 commit comments

Comments
 (0)