N
Nuxt2y ago
Gerbuuun

useFetch adds null to return type

When using useFetch to fetch data from server api routes, useFetch adds null as a union to the return type. Because I use typescript strict mode, this forces me to do null checks to api routes which already handle this. If I understand correctly, when using SSR, useFetch is just an async function call to the api endpoints? Then why does it add null to the type? If this works as intended, how would I check if the data is null inside script setup
No description
No description
7 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Gerbuuun
GerbuuunOP2y ago
A similar problem goes for returning a Date. It becomes a string (because json doesn't support Date?) But typescript still thinks it is a Date which is quite annoying. Are these known issues? Maybe add some transform into the useFetch composable?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Gerbuuun
GerbuuunOP2y ago
The return type changes from Ref<regattas[] | null> to Ref<SerializeObject<UndefinedToOptional<regattas[]>> | null> so something still adds null to the type.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Gerbuuun
GerbuuunOP2y ago
Ok, I thought when using SSR this wouldn't be a problem. So how would I check the data for null? The example given at the top doesn't do anything. Do I need to wrap it in a computed or anything?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server