在Typescript中,可以使用union type 。Union type ,允许将现有的类型和数据存储从一个联盟类型中组合起来。
Union type 用管道(|)符号表示数字和字符串的(数字|字符串)
例如:
let words:(number|string)[]=["one",1,"two","three","four"]; let words1:Array=["one",1,"two",2,"three","four"];
www.haizhuan.tk