TypeScript 枚举

TypeScript 枚举

ts 的枚举类型

枚举类型默认从 0 开始

ts
enum SexType {
    BOY,
    GIRL,
}
console.log(SexType.BOY) // 0
console.log(SexType.GIRL) // 1

枚举编号会自动递增

ts
enum SexType {
    BOY = 2,
    GIRL,
}
console.log(SexType.BOY) // 2
console.log(SexType.GIRL) // 3

枚举可以自定义

ts
enum SexType {
    BOY = "",
    GIRL = "",
}
console.log(SexType.BOY) // 男
console.log(SexType.GIRL) // 女
js数组
使用GitHubActions部署

评论区

评论加载中...