fix(schema): exclude non-serialisable types from app options (#27478)

This commit is contained in:
Daniel Roe 2024-06-07 13:22:19 +01:00 committed by GitHub
parent a4f739f077
commit 5785332626
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 4 deletions

View File

@ -141,12 +141,14 @@ export interface AppConfigInput extends CustomAppConfig {
server?: never
}
type Serializable<T> = T extends Function ? never : T extends Promise<infer U> ? Serializable<U> : T extends Record<string, any> ? { [K in keyof T]: Serializable<T[K]> } : T
export interface NuxtAppConfig {
head: AppHeadMetaObject
layoutTransition: boolean | TransitionProps
pageTransition: boolean | TransitionProps
head: Serializable<AppHeadMetaObject>
layoutTransition: boolean | Serializable<TransitionProps>
pageTransition: boolean | Serializable<TransitionProps>
viewTransition?: boolean | 'always'
keepalive: boolean | KeepAliveProps
keepalive: boolean | Serializable<KeepAliveProps>
}
export interface AppConfig {

View File

@ -15,6 +15,18 @@ export default defineNuxtConfig({
extends: [
'./extends/node_modules/foo',
],
app: {
head: {
// @ts-expect-error Promises are not allowed
title: Promise.resolve('Nuxt Fixture'),
// @ts-expect-error Functions are not allowed
titleTemplate: title => 'test',
},
pageTransition: {
// @ts-expect-error Functions are not allowed
onBeforeEnter: el => console.log(el),
},
},
runtimeConfig: {
baseURL: '',
baseAPIToken: '',

View File

@ -320,6 +320,7 @@ describe('runtimeConfig', () => {
describe('head', () => {
it('correctly types nuxt.config options', () => {
// @ts-expect-error invalid head option
defineNuxtConfig({ app: { head: { titleTemplate: () => 'test' } } })
defineNuxtConfig({
app: {