Reputation: 702
Let says I have a type as follows:
export enum configType {
value = 'blah bala',
value2 = 'blah bala',
value3 = 'blah bala',
value2 = 'blah bala',
}
Now I want to create a new type with above enum as follows:
export type analog = {
[v + '_key' in configType]?: boolean;
}
Would this be possible?
Upvotes: 1
Views: 282
Reputation: 33739
You can do this with literal types the type utilities Record<Keys, Type>
and Partial<Type>
.
enum ConfigType {
Value = 'Value',
Value2 = 'Value2',
Value3 = 'Value3',
Value4 = 'Value4',
}
type Analog = Partial<Record<`${ConfigType}_key`, boolean>>;
/*
type Analog = {
Value_key?: boolean;
Value2_key?: boolean;
Value3_key?: boolean;
Value4_key?: boolean;
}
*/
Upvotes: 1