Property 'url' does not exist on type 'number | Media'
Answered
American black bear posted this in #help-forum
American black bearOP
I'm getting a type error in the line
Despite 'url' definitely being an attribute on type Media. It's throwing an error because it doesn't exist on type number, which it wouldn't. Am I missing something here? Thanks!
backgroundImage: `url(${person.cover_image ? person.cover_image.url : '/coverPlaceholder.jpg'})`,
Despite 'url' definitely being an attribute on type Media. It's throwing an error because it doesn't exist on type number, which it wouldn't. Am I missing something here? Thanks!
Answered by American black bear
You are getting the error because the
You can fix this by ensuring the url exists, or removing the type of number from person_cover_image:
.url
does not exist on type number
even though it exists on Media
type .You can fix this by ensuring the url exists, or removing the type of number from person_cover_image:
backgroundImage: `url(${person.cover_image.url ? person.cover_image.url : '/coverPlaceholder.jpg'})`,
4 Replies
American black bear
You are getting the error because the
You can fix this by ensuring the url exists, or removing the type of number from person_cover_image:
.url
does not exist on type number
even though it exists on Media
type .You can fix this by ensuring the url exists, or removing the type of number from person_cover_image:
backgroundImage: `url(${person.cover_image.url ? person.cover_image.url : '/coverPlaceholder.jpg'})`,
Answer
American black bearOP
I see. So the
number | Media
is defined in the generated payload-types file. Sounds like I just want to override the person's cover_image property and explicitly define it as type Media
American black bear
You can do that or use code example I've given above
American black bearOP
I see, thank you!