我有一个类型
type mytype = 'tipe-1' | 'tipe-2' | 'tipe-3'
如何打字
type mytype2 = '1' | '2' | '3'
但输出还是一样的'tipe-1' | 'tipe-2' | 'tipe-3'
答案 0 :(得分:3)
您可以使用 Template Literal Types:
<listener>
<listener-class>com.config.ServletStartListener</listener-class>
</listener>
这等同于:
type MyType = `tipe-${1 | 2 | 3}`
如果你想在多个地方使用它,你可以抽象它:
type MyType = 'tipe-1' | 'tipe-2' | 'tipe-3'