@@ -211,16 +211,20 @@ async function writeTypes(distDir: string, meta: ModuleMeta, getOptions: () => P
211211 const appShims : string [ ] = [ ]
212212 const schemaShims : string [ ] = [ ]
213213 const moduleImports : string [ ] = [ ]
214+ const moduleDeclarations : string [ ] = [ ]
214215
215216 const hasTypeExport = ( name : string ) => isStub || typeExports . find ( exp => exp . names . includes ( name ) )
216217
217- if ( meta . configKey && hasTypeExport ( 'ModuleOptions' ) ) {
218- moduleImports . push ( 'ModuleOptions' )
218+ if ( meta . configKey ) {
219219 schemaShims . push ( ` interface NuxtConfig { ['${ meta . configKey } ']?: Partial<ModuleOptions> }` )
220220 schemaShims . push ( ` interface NuxtOptions { ['${ meta . configKey } ']?: ModuleOptions }` )
221- }
222- else if ( meta . configKey ) {
223- schemaShims . push ( ` ${ generateTypes ( await resolveSchema ( await getOptions ( ) as InputObject ) , { interfaceName : 'ModuleOptions' } ) } ` )
221+
222+ if ( hasTypeExport ( 'ModuleOptions' ) ) {
223+ moduleImports . push ( 'ModuleOptions' )
224+ }
225+ else {
226+ moduleDeclarations . push ( ` ${ generateTypes ( await resolveSchema ( await getOptions ( ) as InputObject ) , { interfaceName : 'ModuleOptions' } ) } ` )
227+ }
224228 }
225229 if ( hasTypeExport ( 'ModuleHooks' ) ) {
226230 moduleImports . push ( 'ModuleHooks' )
@@ -250,6 +254,7 @@ async function writeTypes(distDir: string, meta: ModuleMeta, getOptions: () => P
250254 const dtsContents = `
251255import type { ${ moduleImports . join ( ', ' ) } } from './module'
252256
257+ ${ moduleDeclarations . join ( '\n' ) }
253258${ appShims . length ? `declare module '#app' {\n${ appShims . join ( '\n' ) } \n}\n` : '' }
254259${ schemaShims . length ? `declare module '@nuxt/schema' {\n${ schemaShims . join ( '\n' ) } \n}\n` : '' }
255260${ schemaShims . length ? `declare module 'nuxt/schema' {\n${ schemaShims . join ( '\n' ) } \n}\n` : '' }
0 commit comments