grouchymachine
grouchymachine
NNuxt
Created by grouchymachine on 12/20/2024 in #❓・help
Describing type for overriden config
Hi All, In a Nuxt app that I work on we rely on config overriding and it works well with Typescript. Unfortunately I encountered problem with describing type for array configs that'll get get overriden. This is the type for the config:
export interface InputConfig {
inputLengths: number[]
}
export interface InputConfig {
inputLengths: number[]
}
This is the initial value for it:
export default {
inputLengths: [8]
} satisfies InputConfig
export default {
inputLengths: [8]
} satisfies InputConfig
And this is the override:
export default {
inputLengths: () => [8, 13]
} satisfies RecursivePartial<InputConfig>
export default {
inputLengths: () => [8, 13]
} satisfies RecursivePartial<InputConfig>
On the override file, I get error from TS saying:
Vue: Type () => number[] is not assignable to type (number | undefined)[]
Vue: Type () => number[] is not assignable to type (number | undefined)[]
I looked into Defu type util, but I have trouble applying it. One othe approach that was suggested is:
export interface InputConfig {
inputLengths: number[] | (() => number[])
}
export interface InputConfig {
inputLengths: number[] | (() => number[])
}
but it changes the type of the actual config and forces additional code around that 😦 Any help would be appreciated.
4 replies