diff --git a/packages/nuxt/src/app/types/augments.d.ts b/packages/nuxt/src/app/types/augments.d.ts index 601fcea877..47fbbf1e23 100644 --- a/packages/nuxt/src/app/types/augments.d.ts +++ b/packages/nuxt/src/app/types/augments.d.ts @@ -1,3 +1,4 @@ +import type { UseHeadInput } from "@unhead/vue"; import type { NuxtApp, useNuxtApp } from '../nuxt' interface NuxtStaticBuildFlags { @@ -33,4 +34,11 @@ declare module 'vue' { _nuxtOnBeforeMountCbs: Function[] _nuxtIdIndex?: Record } + interface ComponentCustomOptions { + /** + * Available exclusively for `defineNuxtComponent`. + * It will not be executed when using `defineComponent`. + */ + head?(nuxtApp: NuxtApp): UseHeadInput + } } diff --git a/test/fixtures/basic-types/types.ts b/test/fixtures/basic-types/types.ts index 429a5d27d6..9a95361b21 100644 --- a/test/fixtures/basic-types/types.ts +++ b/test/fixtures/basic-types/types.ts @@ -329,6 +329,25 @@ describe('head', () => { } }) }) + it('types head for defineNuxtComponent', () => { + defineNuxtComponent({ + head(nuxtApp) { + expectTypeOf(nuxtApp).not.toBeAny() + return { + title: 'Site Title' + } + } + }) + + defineNuxtComponent({ + // @ts-expect-error wrong return type for head function + head() { + return { + 'test': true + } + } + }) + }) }) describe('components', () => {