Skip to content
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

Don't generalize when assigment target is never (fix: #41707) #59774

Merged
merged 4 commits into from
Aug 29, 2024

Conversation

hyzyla
Copy link
Contributor

@hyzyla hyzyla commented Aug 27, 2024

Fixes #41707

Added a condition that when the expected type is "never," the checker should not generalize the literal type. It might not be the best solution, but it's definitely the easiest one. Another idea that I've considered was to check if the "source" type is narrowed and skip generalization for narrowed types, but I'm not sure how to do it properly and if it OK solution.

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Aug 27, 2024
@hyzyla
Copy link
Contributor Author

hyzyla commented Aug 27, 2024

@microsoft-github-policy-service agree

@RyanCavanaugh
Copy link
Member

I think this is a good fix; un-narrowing the source is going to make things more confusing. I can't commit the suggestion to the PR branch for some reason - please merge it in. Behavior changes LGTM.

@RyanCavanaugh RyanCavanaugh merged commit eadb9e1 into microsoft:main Aug 29, 2024
31 of 32 checks passed
@jakebailey
Copy link
Member

jakebailey commented Aug 29, 2024

This was merged skipping checks; not sure that was intended.

@hyzyla I would recommend sending PRs from branches on your fork rather than main; that's why we couldn't modify it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Union of string literals is incorrectly widened in error message when compared to never
5 participants