Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
feat(nuxt): allow exposing type augmentations from extends layers (#7442
Browse files Browse the repository at this point in the history
)
  • Loading branch information
danielroe committed Sep 12, 2022
1 parent 5893dc2 commit 13dc0b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/nuxt/src/core/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/basic/extends/bar/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'bing' {
interface BingInterface {
foo: 'bar'
}
}
6 changes: 6 additions & 0 deletions test/fixtures/basic/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }>()
})
})

0 comments on commit 13dc0b9

Please sign in to comment.