-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Narrowing doesn't recognize string constant as truthy #33878
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
For context, this error occurs when However, note that here The problem lies in that |
Although, strangely, in the case where |
Probably a bug in how we treat the short-circuiting operators when they're nested |
As I pointed out, there is an error even without nesting, which then may be feeding back into the nesting logic. var f = !{b:1}; // :boolean=false (correct)
var m = false && "whatever"; // :boolean=false (correct)
var n = !{b:1} && "whatever"; // :string (wrong) |
This is related to our unreachable code analysis in the binder. We consider false branch of It's not particularly hard to change this, but the question is where to stop. We'd of course have to check string, number, and bigint literals, but also unary I'm not opposed to the change, but also don't think it is particularly high yield. |
TypeScript Version: 3.7-beta
Search Terms: cfa narrowing string truthy
Code
Expected behavior:
The narrowings all work
Actual behavior:
The third narrowing does not work and produces an error
Playground Link:
Playground
Related Issues:
I suspect this is a duplicate, as most CFA narrowing bugs are. But I searched as best I could and didn't find any other bugs that matched what was going on here. It seems like typescript doesn't understand that a non-empty string-literal is true in this situation?
The text was updated successfully, but these errors were encountered: