Update compare types to work when the input is a generic #465
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 #460.
The solution to this ended up being slightly more complex than I thought, because the final two test cases check that it is a type error to compare a
Number
to anumber
There's some weird non-transitive
extends
behavior here , which is why the originalExclude<T, Primitive>
was used.Number extends object
= truenumber extends Number
= truenumber extends object
= falseSo I changed the type parameters to
compare<T1 extends object, T2 extends T1 & object>
, which keeps the tests passing while also allowing it to work with generic arguments.I also added the
types
entry to the export map for compatibility with TS 4.7 node16/nodenext module resolution.