I have data coming in from an API in a Vue 3 Typescript code base. While the data is in transit, I want to know that it's missing. Currently, this is how I do it:
data() {
return {
apiData: null as DataType | null
}
},
async mounted() {
this.apiData = await getData()
}
The issue is defining the type of apiData: null as DataType | null is cumbersome and just feels wrong. I haven't seen any examples of how to do that properly besides a cast like that.
Is there a better way to mark a property of an object as an optional type? I know about interfaces but my objects is a very complex type and that optional data is only one property of it...
Thanks for the help!