mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-16 13:48:13 +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\')'
|
'export const START_LOCATION = Symbol(\'router:start-location\')'
|
||||||
].join('\n')
|
].join('\n')
|
||||||
})
|
})
|
||||||
|
addTypeTemplate({
|
||||||
|
filename: 'types/middleware.d.ts',
|
||||||
|
getContents: () => [
|
||||||
|
'declare module \'nitropack\' {',
|
||||||
|
' interface NitroRouteConfig {',
|
||||||
|
' appMiddleware?: string | string[] | Record<string, boolean>',
|
||||||
|
' }',
|
||||||
|
'}',
|
||||||
|
'export {}'
|
||||||
|
].join('\n')
|
||||||
|
})
|
||||||
addComponent({
|
addComponent({
|
||||||
name: 'NuxtPage',
|
name: 'NuxtPage',
|
||||||
priority: 10, // built-in that we do not expect the user to override
|
priority: 10, // built-in that we do not expect the user to override
|
||||||
@ -464,7 +475,7 @@ export default defineNuxtModule({
|
|||||||
|
|
||||||
addTypeTemplate({
|
addTypeTemplate({
|
||||||
filename: 'types/middleware.d.ts',
|
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 composablesFile = relative(join(nuxt.options.buildDir, 'types'), resolve(runtimeDir, 'composables'))
|
||||||
const namedMiddleware = app.middleware.filter(mw => !mw.global)
|
const namedMiddleware = app.middleware.filter(mw => !mw.global)
|
||||||
return [
|
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
|
// @ts-expect-error Should show error on unknown properties
|
||||||
unknownProp: ''
|
unknownProp: ''
|
||||||
})
|
})
|
||||||
|
defineNuxtConfig({
|
||||||
|
routeRules: {
|
||||||
|
// Should accept any string
|
||||||
|
'/named': { appMiddleware: 'named' }
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
it('core composables', () => {
|
it('core composables', () => {
|
||||||
ref()
|
ref()
|
||||||
|
Loading…
Reference in New Issue
Block a user