-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
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 😄
danvk, lgenzelis, jguddas and ullebe1Rudxainparzhitskycaptain-yossarian, whzx5byb and Rudxain
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript