-
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
3.7-beta regression: Promise.all wrongly adds undefined
type
#33752
Comments
Hm, but maybe #33707 will resolve this regression? That’s what I thought, haven’t checked though. |
Reduced repo: interface A {
a: string
}
interface B {
b: string
}
interface Foo {
all<T1, T2>(values: readonly [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
}
declare const Foo: Foo;
function main() {
let aValue: A;
Foo.all([Promise.resolve({a: "a"} as A), Promise.resolve({b: "b"} as B | undefined)]).then(([a,b]) => aValue = a);
} Error on assignment to |
Yes, the typings in #33707 fix the smaller repro above. |
Here is another case of this: #34554 |
|
@buu700 how do you recommend using that work around? running that command prior to compile every time? @RyanCavanaugh this seems like a pretty major regression, is there any timeline here? I see this immediately on upgrading all around my code base. |
You could use the attached patch with patch-package, or possibly run that sed command (or a JS equivalent) in a postinstall script. |
@buu700 this is amazing. thank you so much for the suggestion extremely helpful! |
I'm seeing a similar situation in Promise.all in 3.7.2 but types are being overwritten. Ex. in the example below r1 should be of type const p1: Promise<boolean> = new Promise((resolve) => { resolve(true); });
const p2: Promise<unknown> = new Promise((resolve) => { resolve(); });
const [r1, r2] = await Promise.all([p1, p2]); If |
Is this not a real issue? I'm getting it, and it seems to me that it is generally pretty disruptive, but I'm not seeing enough MS chatter about it to confirm that it's not just a legit new type error that I don't understand. |
@JasonKleban This is a legit regression. Just updated a codebase and am seeing this. Easily reproducible:
|
Note that Typescript 3.7 seems to have a type inference bug that makes Promise.all() use annoying/breaks existing code compilation (see microsoft/TypeScript#33752, for example) so we're sticking with 3.6 for now
still reproducible in 3.7.3 and nightly |
We are having this issue in 3.7.3 as well. It is blocking our upgrade off of 3.6.x (hundreds of occurrences across the code base). |
@RyanCavanaugh What's the timeline for getting this fixed? |
Is there any reason my fix from November (quoted above) can't or shouldn't be used? I don't mind continuing to patch TypeScript in my own projects as a temporary workaround, but it just seems odd that such a high-impact regression with a simple quick fix available is still an issue three months later. |
tbh, I’m a bit disappointed by the lack of communication here. I recently read the already month old Design notes here: #36138 which mention ideas to create a dedicated |
|
Assuming we merge the |
to slightly clarify the API between this library and its users, add a bit of types where easy. many of the types I've added rely on some "any"s because I'm trying to provide some initial value to make future work easier. a single place uses the non-null assertion operator: apparently there's an open bug in typescript where Promise.all() wrongly adds " | undefined" microsoft/TypeScript#33752 we'll try to keep an eye open here to see when it can be removed.
to slightly clarify the API between this library and its users, add a bit of types where easy. many of the types I've added rely on some "any"s because I'm trying to provide some initial value to make future work easier. a single place uses the non-null assertion operator: apparently there's an open bug in typescript where Promise.all() wrongly adds " | undefined" microsoft/TypeScript#33752 we'll try to keep an eye open here to see when it can be removed.
This issue can be worked around by adding this somewhere: declare global {
interface PromiseConstructor {
all<T extends readonly any[] | readonly [any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]> }>;
}
} but I'd be really happy having this fixed, my devs are using this as an excuse to plaster Bluebird everywhere instead of using native promises. Still exists in 3.9.0-dev.20200229 |
Hopefully this issue will be fixed in 3.9 |
Seems this example still does not work on nightly.
Is it really fixed? |
Just checked on |
@nickzelei Somehow my code above doesn't work on TypeScript playground yet. Perhaps their nightly version is not updated yet. |
The playground seems to have a lot of weirdness there, specifically with |
TypeScript Version: 3.7.0-beta
Search Terms:
promise all
Code
Expected behavior:
This is a regression from 3.6.3, where the return tuple of
Promise.all
is correctly inferred.Actual behavior:
A
| undefined
bound of a different tuple member also adds a| undefined
bound on a different unrelated return value ofPromise.all
.Playground Link:
https://www.typescriptlang.org/play/?ts=3.7-Beta#code/JYOwLgpgTgZghgYwgAgILIN4ChnLgLmQGcwpQBzLAXy1ElkRQCFMdkAjQkskSmuIgE8QCZDACuIsMAD2IZAFs4oABQBKQgAUoMhcCIQAPKgB8rXAjklkAbTgAaDgF1kAXjwB3ZWGTbd+iAA6OAAbEJUbNlw-PQNAqAgiGRCANwgVDAJkACI4bKo8IjQ1eyjfHVighKTU9IxOHPZ8wuQWAB9kSQATCBhQCC6S5AB6YeRDAFpkMAALFAADDu7e-q755DmE5H1pueQABx12EIgFNic1AG42BLBxKHk4S5GxybwNgWnBfYX0JZAen0QAN5o52OIfEQZjJxCEuhxfvNqEA
Related Issues:
Maybe #33707 ?
The text was updated successfully, but these errors were encountered: