enum InputType {
Text = 'text',
Number = 'number'
}
type InputTypeMapping = {
[InputType.Text]: string,
[InputType.Number]: number
}
const inputConfig = {
full_name: {
label: 'Name',
type: InputType.Text
},
age: {
label: 'Age',
type: InputType.Number
}
}
Based on the configuration above, I will render a form to the browser, and the expected output object from the form submission should be like this:
{
full_name: '',
age: 0
}
I want to create the object type for the expected output based on the inputConfig object in the previous snippet. Each key (keyof inputConfig) should mapped to the appropriate input type mapping (typeof InputTypeMapping[inputConfig[key].type]).
I couldn't find a way to create that kind of type. The expected type should be like this ([key in keyof typeof memberInfoKeys] is valid, but the typeof InputTypeMapping[inputConfig[key].type] is invalid, only to give you a picture of what I am expecting)
type FormOutput = {
[key in keyof typeof memberInfoKeys]: typeof InputTypeMapping[inputConfig[key].type]
}
Is there any possible way to create such type in Typescript?