typescript-tutorial
typescript-tutorial copied to clipboard
字符串字面量类型
trafficstars
https://ts.xcatliu.com/advanced/string-literal-types.html
坐个沙发
像枚举
坐个板凳
不一定要字符串吧,Number类型也可以啊: type Nums = 1 | 2 | 3;
事实上不一定要字符串,任意基础类型都是可以的
感觉 类似联合,联合 是类型的限制;type 是值的限制
那么请问,这和 枚举有什么区别嘛??? 感觉枚举也是 取值的限制啊??