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

Overly strict TS typings on just-compare #476

Closed
neil-morrison44 opened this issue Jul 25, 2022 · 1 comment · Fixed by #480
Closed

Overly strict TS typings on just-compare #476

neil-morrison44 opened this issue Jul 25, 2022 · 1 comment · Fixed by #480

Comments

@neil-morrison44
Copy link
Contributor

https://github.com/angus-c/just/blob/fee2bf9/packages/collection-compare/index.d.ts

The typescript typings on this seem to be unrepresentative of the JS functionality
As far as I can tell doing

compare({ a: 12 }, null)

would just return

false

in a pure JS env, but with TS it causes an error

Which isn't too much of an issue if you're passing null manually, but if you've got a value coming from elsewhere with a typing of:

type SomethingThatCouldBeNull = { a: number } | null

and you're trying to use the compare function it'll produce a TS error but (as far as I can tell) the JS handles it and returns false as expected - meaning you have to duplicate the null checks which already happen within compare for both values prior to calling compare.

There's been a couple of contributors contributing to it so I don't want to just raise a PR getting rid of the typings without fully understanding it, but it seems like to me if the goal with the TS typings is to accurately type the JS then this would probably be better served using either unknown or any

@angus-c
Copy link
Owner

angus-c commented Jul 31, 2022

I agree with this. PR welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants