mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(schema): allow type inference of arrays in runtime config (#18931)
* fix(schema): allow type inference of arrays in runtime config * test: add types fixture
This commit is contained in:
parent
9ee568efe6
commit
19bef5aba4
@ -54,7 +54,9 @@ type Overrideable<T extends Record<string, any>, Path extends string = ''> = {
|
||||
? T[K] extends Record<string, any>
|
||||
? RuntimeValue<Overrideable<T[K], `${Path}_${UpperSnakeCase<K>}`>, `You can override this value at runtime with NUXT${Path}_${UpperSnakeCase<K>}`>
|
||||
: RuntimeValue<T[K], `You can override this value at runtime with NUXT${Path}_${UpperSnakeCase<K>}`>
|
||||
: never
|
||||
: K extends number
|
||||
? T[K]
|
||||
: never
|
||||
}
|
||||
|
||||
/** User configuration in `nuxt.config` file */
|
||||
|
1
test/fixtures/basic/nuxt.config.ts
vendored
1
test/fixtures/basic/nuxt.config.ts
vendored
@ -53,6 +53,7 @@ export default defineNuxtConfig({
|
||||
baseAPIToken: '',
|
||||
privateConfig: 'secret_key',
|
||||
public: {
|
||||
ids: [1, 2, 3],
|
||||
needsFallback: undefined,
|
||||
testConfig: 123
|
||||
}
|
||||
|
5
test/fixtures/basic/types.ts
vendored
5
test/fixtures/basic/types.ts
vendored
@ -133,6 +133,7 @@ describe('runtimeConfig', () => {
|
||||
expectTypeOf(runtimeConfig.public.testConfig).toEqualTypeOf<number>()
|
||||
expectTypeOf(runtimeConfig.public.needsFallback).toEqualTypeOf<string>()
|
||||
expectTypeOf(runtimeConfig.privateConfig).toEqualTypeOf<string>()
|
||||
expectTypeOf(runtimeConfig.public.ids).toEqualTypeOf<number[]>()
|
||||
expectTypeOf(runtimeConfig.unknown).toEqualTypeOf<any>()
|
||||
})
|
||||
it('provides hints on overriding these values', () => {
|
||||
@ -140,7 +141,8 @@ describe('runtimeConfig', () => {
|
||||
runtimeConfig: {
|
||||
public: {
|
||||
// @ts-expect-error
|
||||
testConfig: 'test'
|
||||
testConfig: 'test',
|
||||
ids: [1, 2]
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -148,6 +150,7 @@ describe('runtimeConfig', () => {
|
||||
expectTypeOf(val.runtimeConfig!.privateConfig).toEqualTypeOf<undefined | RuntimeValue<string, 'You can override this value at runtime with NUXT_PRIVATE_CONFIG'>>()
|
||||
expectTypeOf(val.runtimeConfig!.baseURL).toEqualTypeOf<undefined | RuntimeValue<string, 'You can override this value at runtime with NUXT_BASE_URL'>>()
|
||||
expectTypeOf(val.runtimeConfig!.baseAPIToken).toEqualTypeOf<undefined | RuntimeValue<string, 'You can override this value at runtime with NUXT_BASE_API_TOKEN'>>()
|
||||
expectTypeOf(val.runtimeConfig!.public!.ids).toEqualTypeOf<undefined | RuntimeValue<Array<number | undefined>, 'You can override this value at runtime with NUXT_PUBLIC_IDS'>>()
|
||||
expectTypeOf(val.runtimeConfig!.unknown).toEqualTypeOf<any>()
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user