given following object:
const myConfig = {
'keyA': { provider: 'Country', validators: [] }, // see RuleDetailsFormBuilderConfiguration type
'myGroup': [
{
'keyB': { provider: 'Country', validators: [] },
'keyC': { provider: 'Country', validators: [] },
'keyD': { provider: 'Country', validators: [] },
}
]
};
interface Test {
keyA: any;
keyB: any;
keyC: any;
keyD: any
}
How would the type/interface for myConfig
look like in TypeScript?
Basically I want to have a combination of [key of generic] : RuleDetailFieldConfig. Additionally it should be possible to define a arbitrary key (in my example myGroup
and give an array of the combination [key of generic] : RuleDetailFieldConfig.
For a concrete example of a generic see the above mentioned interface Test
I'm able to make a type definition for the first line in the object ('keyA': { provider: 'Country', validators: [] }
)
For this my type looks like this:
export interface RuleDetailFieldConfig {
provider: string;
validators: string[];
}
export type RuleDetailsFormBuilderConfiguration<Type> = {
[Property in keyof Type ]: RuleDetailFieldConfig
};
For this part:
'myGroup': [
{
'keyB': { provider: 'Country', validators: [] },
'keyC': { provider: 'Country', validators: [] },
'keyD': { provider: 'Country', validators: [] },
}
] // see RuleDetailsFormGroupBuilderConfiguration
My type looks like this:
export type RuleDetailsFormGroupBuilderConfiguration<Type> = {
[groupname: string] : RuleDetailsFormBuilderConfiguration<Partial<Type>>[]
}
How can I combine these two separate types to have one type for my object?