ts、typescript、enum、枚举、ts 获取枚举对应的类型、获取 enum 的 key 和 value

ts、typescript、enum、枚举、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'

posted @ 2022-07-23 19:37  骚猪佩琦  阅读(8241)  评论(0编辑  收藏  举报