From a256c8740675aca23f3afcd7d41fe9f9b1b3291f Mon Sep 17 00:00:00 2001 From: Maik Kowol Date: Sun, 27 Aug 2023 21:44:43 +0200 Subject: [PATCH] fix(nuxt): ensure typed layout prop persists through build (#22855) --- packages/nuxt/src/app/components/nuxt-layout.ts | 2 +- test/fixtures/basic-types/types.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/app/components/nuxt-layout.ts b/packages/nuxt/src/app/components/nuxt-layout.ts index 82c321479d..752978b2ab 100644 --- a/packages/nuxt/src/app/components/nuxt-layout.ts +++ b/packages/nuxt/src/app/components/nuxt-layout.ts @@ -81,7 +81,7 @@ export default defineComponent({ } } }) as unknown as DefineComponent<{ - name?: unknown extends PageMeta['layout'] ? MaybeRef : PageMeta['layout'] + name?: (unknown extends PageMeta['layout'] ? MaybeRef : PageMeta['layout']) | undefined; }> const LayoutProvider = defineComponent({ diff --git a/test/fixtures/basic-types/types.ts b/test/fixtures/basic-types/types.ts index d0a46e66fa..2adf7b4d34 100644 --- a/test/fixtures/basic-types/types.ts +++ b/test/fixtures/basic-types/types.ts @@ -7,7 +7,7 @@ import type { AppConfig, RuntimeValue } from 'nuxt/schema' import { defineNuxtConfig } from 'nuxt/config' import { callWithNuxt, isVue3 } from '#app' import type { NavigateToOptions } from '#app/composables/router' -import { NuxtLink, NuxtPage, WithTypes } from '#components' +import { NuxtLayout, NuxtLink, NuxtPage, WithTypes } from '#components' import { useRouter } from '#imports' interface TestResponse { message: string } @@ -207,6 +207,13 @@ describe('layouts', () => { // @ts-expect-error Invalid layout definePageMeta({ layout: 'invalid-layout' }) }) + + it('allows typing layouts', () => { + h(NuxtLayout, { name: 'custom' }) + + // @ts-expect-error Invalid layout + h(NuxtLayout, { name: 'invalid-layout' }) + }) }) describe('modules', () => {