Open
Description
Bug Report
🔎 Search Terms
string truthy falsy narrow literal empty
🕗 Version & Regression Information
This is a crashThis changed between versions ______ and _______- This is the behavior in every version I tried, and I reviewed the FAQ for entries about narrowing
I was unable to test this on prior versions because _______
⏯ Playground Link
Playground link with relevant code
💻 Code
let value = Math.random() > 0.5 && "Some Name";
if (!value) {
value; // Type: false | string, but should be false | ""
}
🙁 Actual behavior
Inside the narrowed block, value
should be false | ""
, because no other string value is falsy.
🙂 Expected behavior
It's the more general false | string
instead.
This was a hard issue to search for; #41503, #33878, and #31156 seemed related but not duplicate to me.
Shoutout to RyanCavanaugh for sending me a code snippet that looked like this -- no good deed goes unpunished in the issue tracker 😄