【发布时间】:2021-03-03 17:40:55
【问题描述】:
有没有办法缩短这段代码? 基本上我不想写 A.a、A.b 等。一些我只想写 A 和类型脚本的方式会理解它需要是枚举值之一。
谢谢
enum A {
a: 'one',
b: 'two',
c: 'three'
}
interface check {
type: A.a|A.b|A.c
}
【问题讨论】:
标签: javascript typescript enums interface
有没有办法缩短这段代码? 基本上我不想写 A.a、A.b 等。一些我只想写 A 和类型脚本的方式会理解它需要是枚举值之一。
谢谢
enum A {
a: 'one',
b: 'two',
c: 'three'
}
interface check {
type: A.a|A.b|A.c
}
【问题讨论】:
标签: javascript typescript enums interface
枚举应按以下方式使用
enum A {
a: 'one',
b: 'two',
c: 'three'
}
interface check {
type: A
}
这样,check.type 可以有值 'one', 'two', 'three'
【讨论】: