feat(nuxt): allow exposing type augmentations from extends layers (#7442)

This commit is contained in:
Daniel Roe 2022-09-12 14:41:15 +01:00 committed by GitHub
parent 5893dc201f
commit 13dc0b94c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -57,6 +57,13 @@ async function initNuxt (nuxt: Nuxt) {
// Add module augmentations directly to NuxtConfig
opts.references.push({ path: resolve(nuxt.options.buildDir, 'types/schema.d.ts') })
opts.references.push({ path: resolve(nuxt.options.buildDir, 'types/app.config.d.ts') })
for (const layer of nuxt.options._layers) {
const declaration = join(layer.cwd, 'index.d.ts')
if (fse.existsSync(declaration)) {
opts.references.push({ path: declaration })
}
}
})
// Add import protection

View File

@ -0,0 +1,5 @@
declare module 'bing' {
interface BingInterface {
foo: 'bar'
}
}

View File

@ -182,3 +182,9 @@ describe('app config', () => {
expectTypeOf<AppConfig>().toMatchTypeOf<ExpectedMergedAppConfig>()
})
})
describe('extends type declarations', () => {
it('correctly adds references to tsconfig', () => {
expectTypeOf<import('bing').BingInterface>().toEqualTypeOf<{ foo: 'bar' }>()
})
})