mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-21 21:25:11 +00:00
fix(nuxt): provide appMiddleware types with universal router
This commit is contained in:
parent
4925670dcd
commit
87c0678f99
@ -122,6 +122,17 @@ export default defineNuxtModule({
|
||||
'export const START_LOCATION = Symbol(\'router:start-location\')'
|
||||
].join('\n')
|
||||
})
|
||||
addTypeTemplate({
|
||||
filename: 'types/middleware.d.ts',
|
||||
getContents: () => [
|
||||
'declare module \'nitropack\' {',
|
||||
' interface NitroRouteConfig {',
|
||||
' appMiddleware?: string | string[] | Record<string, boolean>',
|
||||
' }',
|
||||
'}',
|
||||
'export {}'
|
||||
].join('\n')
|
||||
})
|
||||
addComponent({
|
||||
name: 'NuxtPage',
|
||||
priority: 10, // built-in that we do not expect the user to override
|
||||
@ -464,7 +475,7 @@ export default defineNuxtModule({
|
||||
|
||||
addTypeTemplate({
|
||||
filename: 'types/middleware.d.ts',
|
||||
getContents: ({ nuxt, app }: { nuxt: Nuxt, app: NuxtApp }) => {
|
||||
getContents: ({ nuxt, app }) => {
|
||||
const composablesFile = relative(join(nuxt.options.buildDir, 'types'), resolve(runtimeDir, 'composables'))
|
||||
const namedMiddleware = app.middleware.filter(mw => !mw.global)
|
||||
return [
|
||||
|
6
test/fixtures/minimal-types/types.ts
vendored
6
test/fixtures/minimal-types/types.ts
vendored
@ -19,6 +19,12 @@ describe('auto-imports', () => {
|
||||
// @ts-expect-error Should show error on unknown properties
|
||||
unknownProp: ''
|
||||
})
|
||||
defineNuxtConfig({
|
||||
routeRules: {
|
||||
// Should accept any string
|
||||
'/named': { appMiddleware: 'named' }
|
||||
}
|
||||
})
|
||||
})
|
||||
it('core composables', () => {
|
||||
ref()
|
||||
|
Loading…
Reference in New Issue
Block a user