object might be undefined, but have a undefined check
Here is my code, and im getting a "Object is possibly 'undefined'.ts(2532)" error.
messagesWithCoach.data is a json object with the key being a coachId (String), and the value a list of objects
Why am i still getting this error even though im checking if its undefined
8 Replies
i think the problem is you're using
typeof
typeof
anything will always give you a string, so typeof ... !== undefined
will always be true
and won't make typescript do type narrowing
either put the undefined
in quotes or remove the typeof
and it may workalright, lets check and see!
error is persisting
it may also just be the case that ts can't type narrow for an expression that complex
but yeah u can just nullish coalesce before calliing
map
genius!
Thanks for the help, feeling fairly dumb now haha
No problem