docs: add information on how to type custom hooks (#22312)

This commit is contained in:
Julien Huang 2023-07-25 10:25:14 +02:00 committed by GitHub
parent 832796fe1a
commit b650207fa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -73,3 +73,26 @@ export default defineNitroPlugin((nitroApp) => {
::alert{icon=👉} ::alert{icon=👉}
Learn more about available [Nitro lifecycle hooks](/docs/api/advanced/hooks#nitro-app-hooks-runtime-server-side). Learn more about available [Nitro lifecycle hooks](/docs/api/advanced/hooks#nitro-app-hooks-runtime-server-side).
:: ::
## Add additional hooks
You can add additional hooks by augmenting the types provided by Nuxt. This can be useful for modules.
```ts
import { HookResult } from "@nuxt/schema";
declare module '#app' {
interface RuntimeNuxtHooks {
'your-nuxt-runtime-hook': () => HookResult
}
interface NuxtHooks {
'your-nuxt-hook': () => HookResult
}
}
declare module 'nitropack' {
interface NitroRuntimeHooks {
'your-nitro-hook': () => void;
}
}
```