ts获取枚举对应类型

// 列如如下一个枚举
enum ENUM_TYPE {
ALL = ‘all’,
SOME = ‘some’,
LITTLE = ‘little’
}

// 获取枚举的 value
type IValue = ${ENUM_TYPE} // ‘all’ | ‘some’ | ‘little’

// 获取枚举的 key
type IKey = keyof typeof ENUM_TYPE // ‘ALL’ | ‘SOME’ | ‘LITTLE’

参考该分享

你可能感兴趣的:(typescript,前端,typescript)