sodiray / radash

Functional utility library - modern, simple, typed, powerful
https://radash-docs.vercel.app
MIT License
4.19k stars 167 forks source link

Why not use Number.isInteger #427

Closed JonZhang3 closed 4 days ago

JonZhang3 commented 1 week ago

Why not just use Number.isInteger here? https://github.com/sodiray/radash/blob/069b26cdd7d62e6ac16a0ad3baa1c9abcca420bc/src/typed.ts#L35

MarlonPassos-git commented 1 week ago

JonZhang3 I think it's about the type inference. When use only Number.isInteger has not type inference.

image

MarlonPassos-git commented 1 week ago

But about the implementation, it might make sense to use the Number.isInteger.

https://github.com/sodiray/radash/blob/069b26cdd7d62e6ac16a0ad3baa1c9abcca420bc/src/typed.ts#L36

aleclarson commented 1 week ago

Radashi (a maintained fork of Radash) already uses Number.isInteger for its isInt function.

See here: https://github.com/radashi-org/radashi/blob/main/src/typed/isInt.ts

(Note that the (() => …)() function is for tree-shaking, and it gets removed when your code is minified.)

JonZhang3 commented 1 week ago

JonZhang3 I think it's about the type inference. When use only Number.isInteger has not type inference.

image

That's really something I hadn't thought of, thanks for the tip!