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', () => {