0
点赞
收藏
分享

微信扫一扫

Python3.9及以上Pyinstaller 反编译教程(exe转py)

爱喝酒的幸福人 2024-06-05 阅读 5

我有以下枚举(可能是const,也可以不是),我想导出一个联合类型,类似于我硬编码为MyNewOne的类型。如何处理最新的TS?

const enum FieldId {
    Code = 'code',
    Title = 'title',
    Statuses = 'statuses',
}
type MyNewOne = 'code' | 'title' | 'statuses'

方法1

const enum FieldId {
    Code = 'code',
    Title = 'title',
    Statuses = 'statuses',
}
type FieldIdValue = `${FieldId}` //  "code" | "title" | "statuses"
let v:FieldIdValue = "code"
let vBad: FieldIdValue = "" //err

方法2

const enum FieldId {
  Code = 'code',
  Title = 'title',
  Statuses = 'statuses',
}

type ToUnion<T extends Record<string, string | number>> = keyof {
  [Prop in keyof T as `${T[Prop]}`]: Prop
}

type Result = ToUnion<typeof FieldId>
举报

相关推荐

0 条评论