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
![](https://utfs.io/f/c52c371a-2657-4721-9641-a6967bf5841c-n9sy76.48.51.png)
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
![](https://utfs.io/f/bc2b714d-db27-408b-9edb-2db5663b2fdb-n9sy76.53.10.png)
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 ![t3ggLove](https://cdn.discordapp.com/emojis/1008231483233808426.png)
![t3ggLove](https://cdn.discordapp.com/emojis/1008231483233808426.png)