I have a type with key-value pairs, where keys are React component names and values are the values they take as props. What I am trying to do is to type an array of types containing the type field, which is also the exact name of a component, and a getter and setter functions that use component values types.
type ElementValues = {
text: string,
checkbox: boolean
}
type ElementType = keyof ElementValues
type Value<Type extends ElementType> = ElementValues[Type]
type Test = {
[Type in ElementType]: {
type: Type
getter: () => Value<Type>
setter: (value: Value<Type>) => any
}}[ElementType]
const testList: Array<Test> = [{
type: 'checkbox',
getter: () => 'test,
setter: (value) => ({ })
}]
What I can get is the array with elements that do not care about the given component name and take all possible component value types as setter and getter params/return types.
In the above example, getter should require boolean, as for checkbox value, and setter should have a value type of boolean, not boolean | string.