-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Chained promises produce incorrect types #10977
Comments
I can repro this. This made it a bit clearer: function test() {
let p1 = Promise.resolve(new A()); // p1 is Promise<A>
let p2 = p1.then(x => x.json()); // p2 is Promise<A>, but should be promise<any>
let p3 = p2.then(x => x.b); // x is A, but should be any
} The incorrect inference ocurrs on the It looks like a result of the changes to the |
Also, Promise.all is still inferred incorrectly sometimes. |
Just updated from |
same with 2.1.1, |
Another problem I hit and a non-obvious workaround (shortened from RWC) -- function test2() {
return new Promise<number>(resolve => {
fetch('').then(response => {
//without the cast, value below is Response and resolve() errors
//in TS 2.0 value is any since json() returns Promise<any>
return response.json() as Promise<number>;
}).then(value => {
resolve(value);
});
});
} |
This is a major bug ! |
same with 2.1.4, moved to async calls since this bug |
2.0.10 got the same behavior, Had to switch back to 2.0.7 |
@Alexander-Taran, 2.0.10 is not same as 2.1.x in my code. |
You can be explicit and use |
There is a difference between can and must. This is clearly a serious
regression
…On 28 Dec 2016 3:12 AM, "Alexander Ekdahl" ***@***.***> wrote:
You can be explicit and use then which let's you specify the result of
your then block.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#10977 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADimvNfzi4-xpLjxtJYeH8C8SvvbqN26ks5rMTj2gaJpZM4KAGp9>
.
|
This is huge. Could we get an official statement? This is preventing us from upgrading to 2.1 because all of our Promise chains fail to compile. |
The changes made to the definition of I am currently investigating a solution that seems to be giving the right answer in all of these cases, but it needs further testing and discussion before I can put up a PR. |
@mhegazy this isn't fixed for me. I use https://github.com/shlomiassaf/angular2-modal and this module have types problem from above 2.0.10.
If I'm wrong, please, show me a way to fix it. |
I confirm, this issue isn't fixed in latest typescript 2.2.1 This is a huge blocker ! |
It's got 2.3 tag. Fixed in there
…On 27 Feb 2017 5:56 PM, "offirmo" ***@***.***> wrote:
I confirm, this issue isn't fixed in typescript 2.2. This is a huge
blocker !
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#10977 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADimvMxz24xWszvhLYTwIqSmtkCJdHs8ks5rgnOMgaJpZM4KAGp9>
.
|
@MaximBalaganskiy Hm, this is a huge blocker as @Offirmo sad. I can't update typescript and angular because it depends on 2.1 now. Also 2.1 has object spreading :( @mhegazy Why it was moved to 2.3? |
@MaximBalaganskiy 2.3 isn't available in npm yet. Can't wait... |
|
@MaximBalaganskiy Sorry I understood you incorrectly. I thougth 2.3 is unavailable yet. |
According to microsoft/TypeScript#10977 the bug was fixed in TS2.3.
TypeScript Version: nightly (2.1.0-dev.20160918)
Code
Expected behavior:
Compiled without errors
Actual behavior:
Compiled with an error
The text was updated successfully, but these errors were encountered: