Property does not exist on type

Property 'avatar_url' does not exist on type 'GitUser | undefined'.  TS2339

I would like to add a new issue,

it says Property 'avatar_url' does not exist on type 'GitUser | undefined'. TS2339

Yet it is in the interface:

is something wrong with how I defined the selected user state? how can I fix these problems

It could be undefined so this

Isn’t correct, because it says that it’s a string that’s always present. It it’s possibly not there you need to specify that it possibly won’t be there or is optional

Sorry misread the error. Above may still be true, but it’s the GitUser itself that may not be there.

You need to handle the possibility that GitUser itself may be undefined (or null or whatever), at the minute something in your code is assuming it will always exist – ie you are trying to access properties on the GitUser object. That will cause your app to fall over if the GitUser isn’t there, that’s what the error is telling you and why it won’t compile

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.