mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): add types for globally injected $config
object (#20081)
This commit is contained in:
parent
e7623ec0b7
commit
b811742f89
@ -130,7 +130,7 @@ export const schemaTemplate: NuxtTemplate<TemplateContext> = {
|
||||
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<TemplateContext> = {
|
||||
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')
|
||||
}
|
||||
}
|
||||
|
7
test/fixtures/basic/types.ts
vendored
7
test/fixtures/basic/types.ts
vendored
@ -146,6 +146,13 @@ describe('runtimeConfig', () => {
|
||||
expectTypeOf(runtimeConfig.privateConfig).toEqualTypeOf<string>()
|
||||
expectTypeOf(runtimeConfig.public.ids).toEqualTypeOf<number[]>()
|
||||
expectTypeOf(runtimeConfig.unknown).toEqualTypeOf<any>()
|
||||
|
||||
const injectedConfig = useNuxtApp().$config
|
||||
expectTypeOf(injectedConfig.public.testConfig).toEqualTypeOf<number>()
|
||||
expectTypeOf(injectedConfig.public.needsFallback).toEqualTypeOf<string>()
|
||||
expectTypeOf(injectedConfig.privateConfig).toEqualTypeOf<string>()
|
||||
expectTypeOf(injectedConfig.public.ids).toEqualTypeOf<number[]>()
|
||||
expectTypeOf(injectedConfig.unknown).toEqualTypeOf<any>()
|
||||
})
|
||||
it('provides hints on overriding these values', () => {
|
||||
const val = defineNuxtConfig({
|
||||
|
Loading…
Reference in New Issue
Block a user