-
Notifications
You must be signed in to change notification settings - Fork 12.8k
And expression inferrs wrong type. #26468
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
Since the type of let b: boolean;
let s: string;
let x1 = b && s; // string, (which should it be? x1 is undefined)
b = true;
let x2 = b && s; // string
b = false;
let x3 = b && s; // boolean |
With |
@ahejlsberg in non-SNC we should really be keeping the left operand type in the result when it's a primitive |
We've discussed fixing this before, but decided against it because of the breaking change. Do we feel differently about this now? In general, if you care about precise types you really should be using |
I don't recall that discussion. We could check RWC for impact - seems like we'd reveal a ton of subtle bugs |
RWC results were nothing but false positives. Doesn't seem worth breaking at this point. |
TypeScript Version: 3.1.0-dev.201xxxxx
Search Terms:
Code
Expected behavior:
The inferred type of x is boolean | string;
Actual behavior:
The inferred type of x is string;
Playground Link:
https://www.typescriptlang.org/play/#src=let%20b%3A%20boolean%3B%0D%0Alet%20s%3A%20string%3B%0D%0A%0D%0Alet%20x%20%3D%20b%20%26%26%20s%3B
Related Issues:
The text was updated successfully, but these errors were encountered: