Hello everybody!
Kind of stuck on what feels like a somewhat tricky issue:
I define the shape of a config object we use in our company using generics, then I want to provide functions to savely retrieve keys and types of their values from that config.
An example config would look like this:
const config = defineFlagConfig({
"core": {
globalConstants: {
"test": 5
}
},
"override": {
globalConstants: {
test: 10,
"test-2": 20
}
}
})
I then have functions to type safely merge them and retrieve keys.
However I'd like to now only allow putting numbers in there, but also strings and arrays of strings. When accessing a key that holds a string I'd like ts to infer the type properly as a string and not as string | number
I created a tiny reproduction on the playground: See next message
So adding
globalConstants: {
test: 10,
"test-2": 20
"string-test": "my-string"
}
and accessing it should type as follows:
const constant = getGlobalConstantValue("string-test" , merged) -> infered as string
const constant = getGlobalConstantValue("test" , merged) -> infered as number
Thank you!
It's me again, hope you don't mind.