-
Notifications
You must be signed in to change notification settings - Fork 12.8k
wrong type inference in Promise #31266
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
Comments
No, that is not ok: foo.length -> [Object is possibly 'undefined'] |
@GongT You mean the 3rd line? There is no error in the playground, with all optional checks enabled. |
Most likely, related to #9998. |
Yep, see #9998 - we cutoff control flow analysis on function boundaries (mostly), so |
Which makes perfect sense, because in general the compiler can't know when a function will be called--or even how many times. In the specific case of |
let foo: string | undefined;
if (!foo) foo = 'hello';
new Promise(resolve => resolve(foo!.length)); ok,It seems that it is the correct solution |
TypeScript Version: 3.4.3
Search Terms:
Code
Expected behavior:
Actual behavior:
Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: