-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Incorrect union type narrowing with literal types #45661
Comments
I believe this is a duplicate of #34975. Also, |
I think the main problem in the case of this issue @MartinJohns is |
This actually looks separate from the well-known I guess the unsoundness really at play here is just the one about aliasing and excess properties: playground. I don’t think this issue tells us anything we didn’t already know, but this was a pretty insidious example and it took me a minute to figure it out. It’s definitely not great. @MartinJohns got any more related/duplicates we can cross-reference with my analysis? 😁 |
Oh, I get it now. Thank you for the in-depth analysis @andrewbranch. This was very invaluable to me. As I understand in these cases it's safer to just type the callback's return type, not const's type (or both for a good measure). const folders = response.map((folder): Folder => { /* ... */ }) In my mind this issue can be closed 🙂 |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow. |
Bug Report
🔎 Search Terms
narrowing, union types, if branches.
🕗 Version & Regression Information
⏯ Playground Link
Playground Link
💻 Code
🙁 Actual behavior
folders3
assignment does not throw a compile error.🙂 Expected behavior
folders3
should fail on compilation, becauseversion
of typenumber | <missing prop>
should not be assignable to version of type2 | optional undefined
.The text was updated successfully, but these errors were encountered: