Negative cases of getNarrowedType that match the exact type should be filtered out, even when generic #45205
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 removeFirst
(itself), sinceFirst
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]
andExtract<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).