From 57853326260d1b7e1df0bf87bdd40ee20b3c7438 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 7 Jun 2024 13:22:19 +0100 Subject: [PATCH] fix(schema): exclude non-serialisable types from `app` options (#27478) --- packages/schema/src/types/config.ts | 10 ++++++---- test/fixtures/basic-types/nuxt.config.ts | 12 ++++++++++++ test/fixtures/basic-types/types.ts | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/schema/src/types/config.ts b/packages/schema/src/types/config.ts index eaee96bc52..7306c5222e 100644 --- a/packages/schema/src/types/config.ts +++ b/packages/schema/src/types/config.ts @@ -141,12 +141,14 @@ export interface AppConfigInput extends CustomAppConfig { server?: never } +type Serializable = T extends Function ? never : T extends Promise ? Serializable : T extends Record ? { [K in keyof T]: Serializable } : T + export interface NuxtAppConfig { - head: AppHeadMetaObject - layoutTransition: boolean | TransitionProps - pageTransition: boolean | TransitionProps + head: Serializable + layoutTransition: boolean | Serializable + pageTransition: boolean | Serializable viewTransition?: boolean | 'always' - keepalive: boolean | KeepAliveProps + keepalive: boolean | Serializable } export interface AppConfig { diff --git a/test/fixtures/basic-types/nuxt.config.ts b/test/fixtures/basic-types/nuxt.config.ts index 75c3211841..983039bcdf 100644 --- a/test/fixtures/basic-types/nuxt.config.ts +++ b/test/fixtures/basic-types/nuxt.config.ts @@ -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: '', diff --git a/test/fixtures/basic-types/types.ts b/test/fixtures/basic-types/types.ts index 586fb7c528..dad52b4f6a 100644 --- a/test/fixtures/basic-types/types.ts +++ b/test/fixtures/basic-types/types.ts @@ -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: {