You can use TS "in" operator and do this:
enum Options {
ONE = 'one',
TWO = 'two',
THREE = 'three',
}
interface OptionRequirement {
someBool: boolean;
someString: string;
}
type OptionRequirements = {
[key in Options]: OptionRequirement; // Note the "in" operator.
}
More about the in operator
Answer from Nacho Justicia Ramos on Stack OverflowYou can use TS "in" operator and do this:
enum Options {
ONE = 'one',
TWO = 'two',
THREE = 'three',
}
interface OptionRequirement {
someBool: boolean;
someString: string;
}
type OptionRequirements = {
[key in Options]: OptionRequirement; // Note the "in" operator.
}
More about the in operator
Answer from Nacho Justicia Ramos on stackoverflow.comIt should be:
type Stats = {[key in 'attack'|'defense']: number}
But why not just do this:
type Stats = {
attack: number,
defense: number,
}
?
More readable.