-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Wrong type with Promise chaining #12409
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
Labels
Duplicate
An existing issue was already created
Comments
@tkrotoff I'm not sure if it's an issue or a feature but the recent changes to createHello()
.then<any>(hello => hello.world())
.then(message => {
console.log(message); // Now message is of type any
}); |
Duplicate of #10977 I think |
tkrotoff
added a commit
to tkrotoff/DefinitelyTyped
that referenced
this issue
Dec 14, 2016
See Wrong type with Promise chaining and 2.1.4 microsoft/TypeScript#12409
greglo
pushed a commit
to greglo/DefinitelyTyped
that referenced
this issue
Dec 15, 2016
See Wrong type with Promise chaining and 2.1.4 microsoft/TypeScript#12409
TypeScript 2.2 Promise implementation is still broken, example: interface Toto {}
const promise = new Promise<Toto>((resolve, reject) => {
resolve('toto');
});
promise
.then(value => { // value is of type Toto => OK
console.log('then1 value=', value);
return 'titi';
})
.then(value => { // value is of type Toto => KO, should be 'titi' or string
console.log('then2 value=', value);
return 2;
})
.then(value => { // value is of type Toto => KO, should be 2 or number
console.log('then3 value=', value);
}); Verification by executing the code inside Chrome DevTools:
Solution for now: promise
.then<string>(value => {
console.log('then1 value=', value);
return 'titi';
})
.then<number>(value => {
console.log('then2 value=', value);
return 2;
})
.then(value => {
console.log('then3 value=', value);
}); |
The fix is in version 2.3, not 2.2. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
With 2.1.4 (edit: first reported with [email protected]):
On TypeScript playground, no problem (edit: this is not true anymore, was working with 2.0.10, not with 2.1.4): https://www.typescriptlang.org/play/index.html#src=declare%20function%20createHello()%3A%20Promise%3CHello%3E%3B%0D%0A%0D%0Ainterface%20Hello%20%7B%0D%0A%20%20world()%3A%20Promise%3Cany%3E%3B%0D%0A%7D%0D%0A%0D%0AcreateHello()%0D%0A%20%20.then(hello%20%3D%3E%20hello.world())%0D%0A%20%20.then(message%20%3D%3E%20%7B%0D%0A%20%20%20%20console.log(message)%3B%20%2F%2F%20message%20is%20of%20type%20any%20%3D%3E%20works%0D%0A%20%20%7D)%3B%0D%0A
(for the little story, the bug was found here: DefinitelyTyped/DefinitelyTyped#12808 (comment))
The text was updated successfully, but these errors were encountered: