Closed
Description
With 2.1.4 (edit: first reported with typescript@2.2.0-dev.20161121):
declare function createHello(): Promise<Hello>;
interface Hello {
world(): Promise<any>;
}
createHello()
.then(hello => hello.world())
.then(message => {
console.log(message); // BUG: message is of type Hello instead of any
});
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))
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Wrong type detection with Promise chaining and typescript@2.2.0-dev.20161121[/-][+]Wrong type with Promise chaining and typescript@2.2.0-dev.20161121[/+]brandedoutcast commentedon Nov 26, 2016
@tkrotoff I'm not sure if it's an issue or a feature but the recent changes to
then
callback might be breaking code & the alternative I see is to use the generic version ofthen<TResult>
.Breaking changes
jwbay commentedon Dec 2, 2016
Duplicate of #10977 I think
[-]Wrong type with Promise chaining and typescript@2.2.0-dev.20161121[/-][+]Wrong type with Promise chaining and 2.1.4[/+]Fix TypeScript error with version 2.1.4
Fix TypeScript error with version 2.1.4
tkrotoff commentedon Feb 24, 2017
TypeScript 2.2 Promise implementation is still broken, example:
Verification by executing the code inside Chrome DevTools:
Solution for now:
jwbay commentedon Feb 24, 2017
The fix is in version 2.3, not 2.2.
[-]Wrong type with Promise chaining and 2.1.4[/-][+]Wrong type with Promise chaining[/+]