Best practices for asserting Typescript types for relationships
Unanswered
Braque du Bourbonnais posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Braque du BourbonnaisOP
When fetching data from the API using
Right now, I'm casting the props like the attached image. However, then I need to cast again or use
depth=1
or more, how can I assert that the response has all the relationships filled in rather than strings? Typescript properly assumes every relationship is string | Media
for example, but I know that the value is Media
, because I provided depth=1
.Right now, I'm casting the props like the attached image. However, then I need to cast again or use
ts-ignore
when I'm using the component. What's the best practice for asserting Typescript types when you know something is one of the optional values?![Image](https://cdn.discordapp.com/attachments/1138466711037825066/1138466711285280789/board-with-phone.tsx_paper-triangles-site-Tuesday-August-08-2023-09.36.01AM2x.png)