What does “keyof typeof” mean in TypeScript?

后端 未结 4 1169
渐次进展
渐次进展 2020-12-24 00:11

Example:

Explain to me what keyof typeof means in TypeScript

enum ColorsEnum {
    white = \'#ffffff\',
    black = \'#000000\',
}

type         


        
4条回答
  •  無奈伤痛
    2020-12-24 00:47

    An enum creates an instantiated object. With typeof we get the auto generated type of this enum.

    Now we can get all indices with keyof to make sure Colors can only contain one of them.

提交回复
热议问题