Am a few years late to the party, but this little TypeScript snippet remains one of the most useful day to day helpers.
Since I learned about, it’s become a util in almost every codebase I’ve worked on, almost a calling card I was there 😅
If you need a few more goodies, you can skip the copy paste and install @echo_rm’s ts-is-present. It has a few more utils like hasPresentKey
and hasPresentValue
which are just as useful, but I usually get away with isPresent
for 99% of things.
As a dependency it might approaching left-pad levels, but it’s a staple for me. I almost feel like it should come with TypeScript itself.
So so often I need to map arrays with objects, and isPresent
is IMO the best way to do it.
Not sure I use anything else as often,
And I really only use it in the context of array filtering,
Useful stuff.