-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression: Argument of type 'awaited T' is not assignable to parameter of type 'T' #37534
Comments
This is a correct error. You could have written code like this: declare const arr: Array<() => Promise<Promise<string>>>;
async function fn() {
// x: Array<Promise<string>>
const x = await runSequentially(arr);
// Crashes
x[0].then(() => { });
} There are some workaround available (adding a constraint to |
We don't want to add the flag unless we really need it. Assessing what kind of breaks people encounter in real codebases is how we're figuring that out. |
Is there any real world example that this is unsound in? Because a Personally, I consider that Typescript allows |
Hm... awaited operator is effective to find a bug but correcting for awaited operator was very bored. |
Sure, any higher-order type operation involving // Previously-allowed but unsound definition
async function myAwaitWrong<T>(arg: Promise<T>): Promise<T[]> {
// Proposed: That this be valid without a type assertion
return [await arg] as any;
}
// Correct definition of an awaiting function
async function myAwaitRight<T>(arg: Promise<T>): Promise<(awaited T)[]> {
return [await arg];
}
// Toggle these to observe different behavior
const myAwait = myAwaitRight;
// const myAwait = myAwaitWrong;
class MyThing<T> {
value!: T;
// Returns Promise<T>
async getValue() {
return this.value;
}
// Returns Promise<T[]>
async doSomething() {
return myAwait(this.getValue());
}
}
async function f() {
const p = new MyThing<Promise<string>>();
// Under myAwaitWrong - m: Incorrectly Promise<string>[]
// Under myAwaitRight - m: Correctly string[]
const m = await p.doSomething();
}
People keep saying this and I continually question what it means for this to be the case; it's like saying |
May I ask a question? Can I make the following type check?
I'm using typescript 3.9.0-dev.20200324. |
You have to change the return type to |
@falsandtru It causes |
TypeScript Version: 3.9.0-dev.20200322
Search Terms:
awaited
Code
Expected behavior:
The above code should compile. The types area reasonable and it did compile in previous versions without awaited.
Actual behavior:
Type error on
await executor()
:Playground Link: Playground Link
Related Issues: #37526
The text was updated successfully, but these errors were encountered: