Here is an example of my custom Enum:
export enum MyCustomEnum {
Item1 = 'Item 1',
Item2 = 'Item 2',
Item3 = 'Item 3',
Item4 = 'Item 4',
Item5 = 'Item 5',
}
I am trying to define a type for the following object structure:
const sampleData = {
data1: {
Item1: 'Item 1',
Item2: 'Item 2',
},
data2: {
Item1: 'Item 1',
Item2: 'Item 2',
Item3: 'Item 3',
Item4: 'Item 4',
},
data3: {
Item1: 'Item 1',
Item2: 'Item 2',
Item4: 'Item 4',
},
};
Up until now, I have come up with the following:
type FilteredSelections = {
[key: string]: Partial<{
[key in MyCustomEnum]: string
}>
};
How can I replace the string
in [key in MyCustomEnum]: string
with the specific value associated with each key?
For instance, if the key is Item1
, the corresponding value should be only 'Item 1'
and so forth.
In addition, the values (objects with enum keys and values) belonging to the keys (e.g. data1
, data2
) within sampleData
should align with those within the MyCustomEnum
enumeration. Not all enum values need to be present (partial), but random key-value pairs beyond the enum key-value combinations should not be allowed. Thank you in advance!