An index signature parameter type cannot be a union type. Consider using a mapped object type instead

后端 未结 6 1759
离开以前
离开以前 2020-12-03 16:57

I\'m trying to use the following pattern:

enum Option {
  ONE = \'one\',
  TWO = \'two\',
  THREE = \'three\'
}

interface OptionRequirement {
  someBool: bo         


        
6条回答
  •  醉梦人生
    2020-12-03 17:12

    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 that "key in".
    }
    

提交回复
热议问题