mesqueeb / is-what

JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.
https://mesqueeb.github.io/is-what/
MIT License
169 stars 18 forks source link

Is function isObjectLike checks the type? #15

Closed polemius closed 3 years ago

polemius commented 3 years ago

From documentation I am not quite understanding what really do isObjectLike?

Documentation says Returns whether the payload is an object like a type passed in < >

I can see that If I passed not an object then it will return the false:

isObjectLike<{a: string}>(true) // false

But If I passed some object it will return the true any way:

isObjectLike<{a: string}>({b: 3}) // true

Link to TS playgound

mesqueeb commented 3 years ago

@polemius yeah, I once long ago used it to make some manual type casting easier.

with the hope to one day improve it to have it actually check the object itself, but soon I realised that that's an extremely complex issue and kind of out of scope :S

But back in the day I found it prettier to do type casting with that isObjectLike as opposed to casting something to any.

polemius commented 3 years ago

@mesqueeb I understand now. Thank you for explanation