typescript-tutorial icon indicating copy to clipboard operation
typescript-tutorial copied to clipboard

字符串字面量类型

Open xcatliu opened this issue 5 years ago • 7 comments
trafficstars

https://ts.xcatliu.com/advanced/string-literal-types.html

xcatliu avatar Jun 08 '20 12:06 xcatliu

坐个沙发

Mryang119 avatar Oct 04 '20 09:10 Mryang119

像枚举

ChieseBluceLee avatar Oct 23 '20 06:10 ChieseBluceLee

坐个板凳

barry1102 avatar Nov 18 '20 02:11 barry1102

不一定要字符串吧,Number类型也可以啊: type Nums = 1 | 2 | 3;

Shyng avatar Nov 26 '20 03:11 Shyng

事实上不一定要字符串,任意基础类型都是可以的

JackyM06 avatar Jan 04 '21 07:01 JackyM06

感觉 类似联合,联合 是类型的限制;type 是值的限制

huanshiwushuang avatar Jan 16 '21 01:01 huanshiwushuang

那么请问,这和 枚举有什么区别嘛??? 感觉枚举也是 取值的限制啊??

huanshiwushuang avatar Jan 17 '21 12:01 huanshiwushuang