diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index 603c8ae0c0..33c031cd08 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -130,7 +130,7 @@ export const schemaTemplate: NuxtTemplate = { const modules = moduleInfo.map(meta => [genString(meta.configKey), getImportName(meta.importName)]) return [ - "import { NuxtModule } from 'nuxt/schema'", + "import { NuxtModule, RuntimeConfig } from 'nuxt/schema'", "declare module 'nuxt/schema' {", ' interface NuxtConfig {', ...modules.map(([configKey, importName]) => @@ -154,7 +154,18 @@ export const schemaTemplate: NuxtTemplate = { allowExtraKeys: false, indentation: 2 }), - '}' + '}', + `declare module 'vue' { + interface ComponentCustomProperties { + $config: RuntimeConfig + } + }`, + // TODO: remove when webstorm has support for augumenting 'vue' directly + `declare module '@vue/runtime-dom' { + interface ComponentCustomProperties { + $config: RuntimeConfig + } + }` ].join('\n') } } diff --git a/test/fixtures/basic/types.ts b/test/fixtures/basic/types.ts index 7fdaa943b1..df0d3007e5 100644 --- a/test/fixtures/basic/types.ts +++ b/test/fixtures/basic/types.ts @@ -146,6 +146,13 @@ describe('runtimeConfig', () => { expectTypeOf(runtimeConfig.privateConfig).toEqualTypeOf() expectTypeOf(runtimeConfig.public.ids).toEqualTypeOf() expectTypeOf(runtimeConfig.unknown).toEqualTypeOf() + + const injectedConfig = useNuxtApp().$config + expectTypeOf(injectedConfig.public.testConfig).toEqualTypeOf() + expectTypeOf(injectedConfig.public.needsFallback).toEqualTypeOf() + expectTypeOf(injectedConfig.privateConfig).toEqualTypeOf() + expectTypeOf(injectedConfig.public.ids).toEqualTypeOf() + expectTypeOf(injectedConfig.unknown).toEqualTypeOf() }) it('provides hints on overriding these values', () => { const val = defineNuxtConfig({