-
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
Promise being resolved with wrong type #9991
Comments
I'm also seeing this :) Not sure why the type is not being respected. TS 2.6.2
|
@badescuga any is a catch all and will totally break type safety. Got me last week. The more definitions you introduce in your code the better. You can also use noImplicitAny to pick up on these errors. |
This has been fixed |
TypeScript Version: Version 3.6.3 Just a reminder, while the fix works for most practical cases, it still doesn't detect type inconsistencies for interface Message { }
function getPromise(): Promise<Message> {
return new Promise(resolve => {
resolve(1234); // Should fail as 'abcd' is not a Message
});
}
getPromise().then(s => {
console.log(s.length); // fails as length is not a property of Message
}); |
TypeScript Version: 1.8.10 and 2.0.0 beta
Code
Expected behaviour: A compile error on line 3
Actual behaviour: The program prints
undefined
If I copy the type definition of
resolve
from the interfacePromiseConstructor
(in lib.es6.d.ts), I get the expected behaviour:The text was updated successfully, but these errors were encountered: