Use Enum as restricted key type in Typescript

前端 未结 3 1419
悲&欢浪女
悲&欢浪女 2021-02-05 01:19

The question is can enum be used as a key type instead of only \"number\" or \"string\" ? Currently it seems like the only possible declaration is x:{[key:number]:any} where key

3条回答
  •  猫巷女王i
    2021-02-05 01:56

    For those who are seeking for a way to get the keys of the enum instead its value, you just need to change from this:

    type myType = Partial>;
    

    to that:

    type myType = Partial>;
    

提交回复
热议问题