-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
only null Type is allowed to useAsyncData's default Type #21277
Comments
I'm not 100% sure what you mean. Is the issue that when you provide a default value, the type of |
I think that you probably will avoid typescript errors in this way. const { data, pending, refresh } = useAsyncData(() => $fetch<User>('/users/1'), {
default: (): User => ({
name: '',
auth: '',
}),
}) |
@danielroe sorry if my sentences confusing you. English is so hard to me😢 here is part of asyncData.d.ts
@aaharu thank you for your answer but it still does not work maybe something wrong in my develope environment? i'm work with visual studio code with volar currently the only way i found is
|
It seems like I have the same problem: await useAsyncData<Taxon[]>('brands', () =>
$fetchApi('/api/v2/shop/taxons'),
{
default: () => [],
}
) I have tried to pass |
Would you provide a code reproduction? 🙏 |
@Applelo await useAsyncData('brands', () =>
$fetchApi('/api/v2/shop/taxons') as Promise<Taxon[]>,
{
default: (): Taxon[] => [],
}
) |
@aaharu Ok so I have move the useAsyncData('brands', () =>
$fetchApi<Taxon[]>('/api/v2/shop/taxons'),
{
default: () => [],
}) I don't know if it's relevant to do a reproduction ? Should my previous code work with typing pass in useAsyncData<Taxon[]>() If so, I can make a reproduction. |
it's still not solved to me.... so can i ask a one? tell me if i was wrong. this is from #20968 in asyncData type https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/asyncData.ts i see all DefaultT's initial type is null
for fix this type problem, all these DefaultT's initial type sholdn't be follow Data's type?
please check this one if you have any times. thanks |
Environment
Reproduction
i tried to reproduction but it doesn't show typescript error
Describe the bug
sorry my english is bad...
when i use useAsyncData with default data
it shows typescript error
so i checked useAsyncData's Type
there are two ways i found
so i wonder it's any reason to default option's default type is null ?
i think it could be better with
or i awalys have to generate default type when use useAsyncData
and i also checked nuxt.com api document and it looks like what i said
sorry if i was wrong and thank you for the amazing job!
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: