TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

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

Open hyzyla opened this issue 1 year ago • 2 comments

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.

hyzyla avatar Aug 27 '24 16:08 hyzyla

@microsoft-github-policy-service agree

hyzyla avatar Aug 27 '24 16:08 hyzyla

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 avatar Aug 27 '24 16:08 RyanCavanaugh

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.

jakebailey avatar Aug 29 '24 21:08 jakebailey