An index signature parameter type cannot be a union type. Consider using a mapped object type instead
- 2020/09/10
- JavaScript
An index signature parameter type cannot be a union type. Consider using a mapped object type insteadのエラーがでる
enum Option {
ONE = 'one',
TWO = 'two',
THREE = 'three'
}
interface OptionRequirement {
someBool: boolean;
someString: string;
}
interface OptionRequirements {
[key: Option]: OptionRequirement;
}
key in を使用することで回避できる
enum Options {
ONE = 'one',
TWO = 'two',
THREE = 'three',
}
interface OptionRequirement {
someBool: boolean;
someString: string;
}
type OptionRequirements = {
[key in Options]: OptionRequirement; // Note that "key in".
}