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

Is function isObjectLike checks the type? #15

Closed
polemius opened this issue Dec 21, 2020 · 2 comments
Closed

Is function isObjectLike checks the type? #15

polemius opened this issue Dec 21, 2020 · 2 comments

Comments

@polemius
Copy link

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
Copy link
Owner

mesqueeb commented Feb 19, 2021

@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
Copy link
Author

@mesqueeb I understand now. Thank you for explanation

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

No branches or pull requests

2 participants