How to check if type is array?
I have the following interface
How can I check if i'm dealing with the object type or the string[] type while mapping through the key's of IFilterOptions
ie:
9 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
This would also work.
Exactly what I needed. Could you explain why this does work as opposed to what I had first though?
Also thanks for this, gonna read through it when I have some time
Cannot say for certain TBH.
What I do know is that in my version of it, I'm directly passing the value into the
Array.isArray
vs accessing the reference of it on the object outside of the context of the .forEach
.Yea that could be the reason. Thanks!!
Trying to implement it with type predicates, as it seems like the cleaner solution, but having some trouble.
I made the following guard:
Which should guarantee that it is specifically of type
{min: number; max:number}
yet
I think the Object.keys().forEach() is messing with the outcome of thisUnknown User•2y ago
Message Not Public
Sign In & Join Server To View
Yeah. Handling them individually without Object.keys works. Guess it's not much of a problem. Wanted to make it more generic in case I added more filters later on, but not too big a deal. Learnt something new, type predicates. Thanks 😉
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Oh that makes so much sense, what an oversight haha. I'll try it out tomorrow, thanks a lot