You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Type '"" | Date' is not assignable to type 'Date'. Type 'string' is not assignable to type 'Date'. ts(2322)
This is wrong because it's inside a conditional block that narrows out the empty-string type from inputArray[index].
🙂 Expected behavior
The first example works just fine, with narrowing of the type working just as it does in the second.
Related issues
I don’t think this is a duplicate of #9998, despite how common duplicates are. This isn’t about other functions modifying the state or possibly expanding the type of a variable beyond a narrowing; there aren’t even multiple function calls involved. It’s not asynchronous, which was recently held to be a distinguishing feature of #9998.
I don’t think this is a duplicate of #18758 which is about narrowing the type of the parent based on the type/presence of deeper members, which is more complicated than what’s sought here, which is narrowing a specific member of an array rather than its parent.
The text was updated successfully, but these errors were encountered:
Bug Report
🔎 Search Terms
narrowing array member object element
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about "Common "Bugs" That Aren't Bugs" and "Common Feature Requests"
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Error on line 5 (the most indented line):
This is wrong because it's inside a conditional block that narrows out the empty-string type from
inputArray[index]
.🙂 Expected behavior
The first example works just fine, with narrowing of the type working just as it does in the second.
Related issues
I don’t think this is a duplicate of #9998, despite how common duplicates are. This isn’t about other functions modifying the state or possibly expanding the type of a variable beyond a narrowing; there aren’t even multiple function calls involved. It’s not asynchronous, which was recently held to be a distinguishing feature of #9998.
I don’t think this is a duplicate of #18758 which is about narrowing the type of the parent based on the type/presence of deeper members, which is more complicated than what’s sought here, which is narrowing a specific member of an array rather than its parent.
The text was updated successfully, but these errors were encountered: