fix(nuxt): add missing type for head in defineNuxtComponent (#25410)

This commit is contained in:
Mateusz Kulpa 2024-02-22 12:11:44 +01:00 committed by GitHub
parent 0152cf48eb
commit b5981f6840
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 0 deletions

View File

@ -1,3 +1,4 @@
import type { UseHeadInput } from "@unhead/vue";
import type { NuxtApp, useNuxtApp } from '../nuxt' import type { NuxtApp, useNuxtApp } from '../nuxt'
interface NuxtStaticBuildFlags { interface NuxtStaticBuildFlags {
@ -33,4 +34,11 @@ declare module 'vue' {
_nuxtOnBeforeMountCbs: Function[] _nuxtOnBeforeMountCbs: Function[]
_nuxtIdIndex?: Record<string, number> _nuxtIdIndex?: Record<string, number>
} }
interface ComponentCustomOptions {
/**
* Available exclusively for `defineNuxtComponent`.
* It will not be executed when using `defineComponent`.
*/
head?(nuxtApp: NuxtApp): UseHeadInput
}
} }

View File

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