diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index 25bd2c0e6a23..e8b76fe278ae 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -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', + ' }', + '}', + '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 [ diff --git a/test/fixtures/minimal-types/types.ts b/test/fixtures/minimal-types/types.ts index 21feaeac4ffa..53232a4e76d3 100644 --- a/test/fixtures/minimal-types/types.ts +++ b/test/fixtures/minimal-types/types.ts @@ -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()