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

Update compare types to work when the input is a generic #465

Merged
merged 1 commit into from
Jun 12, 2022

Conversation

dimfeld
Copy link
Contributor

@dimfeld dimfeld commented Jun 6, 2022

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 a number

There's some weird non-transitive extends behavior here , which is why the original Exclude<T, Primitive> was used.

  • Number extends object = true
  • number extends Number = true
  • number extends object = false

So 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.

@angus-c
Copy link
Owner

angus-c commented Jun 12, 2022

Thanks this is great!
Published as [email protected]

@angus-c angus-c merged commit fee2bf9 into angus-c:master Jun 12, 2022
@dimfeld dimfeld deleted the compare-types-update branch June 13, 2022 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

just-compare types don't work with generics
2 participants