Skip to content

Negative cases of getNarrowedType that match the exact type should be filtered out, even when generic - #45205

Closed
Wesley Wigham (weswigham) wants to merge 1 commit into
microsoft:mainfrom
weswigham:generic-guard
Closed

Negative cases of getNarrowedType that match the exact type should be filtered out, even when generic#45205
Wesley Wigham (weswigham) wants to merge 1 commit into
microsoft:mainfrom
weswigham:generic-guard

Conversation

@weswigham

@weswigham Wesley Wigham (weswigham) commented Jul 27, 2021

Copy link
Copy Markdown
Member

Fixes #44404

The reported regression is caused by the changes in #43763 - in breaking apart constraints in negative cases, we made it so First (a generic) could never remove First (itself), since First is constrained to {foo: string} (yet obviously isn't related to the generic subtype in question). With this change to that, we do not perform the constraint check if the candidate exactly matches - this is easily foiled (by subtypes and intersections).

See, the thing is - after some investigation, I've decided this is a kind of hacky fix layered on a hacky fix.
#43763 is ultimately doing the best it can to work around the fact that the subtype comparison result for Slice[A][B] and Extract<Slice[A][B]. whatever> is wrong - a root cause bug which #41821 fixes. I think, rather than this, we should be looking to pull in #41821 and completely revert the non-test changes in #43763 (since I can confirm the issue is also fixed by #41821). That combined change can be found here, if we think we'd like to do that, instead (the relevant diff has been merged into #41821).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Union types are not being narrowed correctly in generic functions in 4.3

3 participants