-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
fix(nuxt): generate correct types for async data defaults based on nuxt.config
#32324
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
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the generation of types for async data defaults to correctly use the configured values when v4 compatibility mode is enabled.
- Updated the type generation logic in Nuxt templates for async data and error value defaults based on nuxt.config settings.
- Introduced nested ternary expressions to select between null and undefined for v4 compatibility.
Comments suppressed due to low confidence (1)
packages/nuxt/src/core/templates.ts:108
- In non-v4 mode, the default now returns 'undefined' instead of the previous 'null'. Please verify that this behavior aligns with the intended API design.
type DefaultAsyncDataErrorValue = ${ isV4 ? ctx.nuxt.options.experimental.defaults.useAsyncData.errorValue === 'null' ? null : undefined : undefined }
packages/nuxt/src/core/templates.ts
Outdated
return ` | ||
declare module 'nuxt/app/defaults' { | ||
type DefaultAsyncDataErrorValue = ${isV4 ? 'undefined' : 'null'} | ||
type DefaultAsyncDataValue = ${isV4 ? 'undefined' : 'null'} | ||
type DefaultAsyncDataErrorValue = ${ | ||
isV4 | ||
? ctx.nuxt.options.experimental.defaults.useAsyncData.errorValue === 'null' | ||
? null | ||
: undefined | ||
: undefined | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The nested ternary operator here reduces readability; consider refactoring by extracting the logic into a helper or using clearer conditional constructs.
Copilot uses AI. Check for mistakes.
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #32324 will not alter performanceComparing Summary
|
🔗 Linked issue
resolves #32213
📚 Description
Correctly generates types for chosen async data/data error value when v4 compat mode is enabled.