Skip to content

Commit 87c0678

Browse files
committedMar 16, 2024··
fix(nuxt): provide appMiddleware types with universal router
1 parent 4925670 commit 87c0678

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
 

‎packages/nuxt/src/pages/module.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ export default defineNuxtModule({
122122
'export const START_LOCATION = Symbol(\'router:start-location\')'
123123
].join('\n')
124124
})
125+
addTypeTemplate({
126+
filename: 'types/middleware.d.ts',
127+
getContents: () => [
128+
'declare module \'nitropack\' {',
129+
' interface NitroRouteConfig {',
130+
' appMiddleware?: string | string[] | Record<string, boolean>',
131+
' }',
132+
'}',
133+
'export {}'
134+
].join('\n')
135+
})
125136
addComponent({
126137
name: 'NuxtPage',
127138
priority: 10, // built-in that we do not expect the user to override
@@ -464,7 +475,7 @@ export default defineNuxtModule({
464475

465476
addTypeTemplate({
466477
filename: 'types/middleware.d.ts',
467-
getContents: ({ nuxt, app }: { nuxt: Nuxt, app: NuxtApp }) => {
478+
getContents: ({ nuxt, app }) => {
468479
const composablesFile = relative(join(nuxt.options.buildDir, 'types'), resolve(runtimeDir, 'composables'))
469480
const namedMiddleware = app.middleware.filter(mw => !mw.global)
470481
return [

‎test/fixtures/minimal-types/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ describe('auto-imports', () => {
1919
// @ts-expect-error Should show error on unknown properties
2020
unknownProp: ''
2121
})
22+
defineNuxtConfig({
23+
routeRules: {
24+
// Should accept any string
25+
'/named': { appMiddleware: 'named' }
26+
}
27+
})
2228
})
2329
it('core composables', () => {
2430
ref()

0 commit comments

Comments
 (0)
Please sign in to comment.