Tuple
基础
let x:[string,number];x = ['hello',123];可以使用对应的方法x[0].substr(0);
元组越界
x[3] = 'world'; //出现错误,没有定义,undefined无法分配给stringx.push(false); //出错x.push(222); //没报错,元组push的必须是之前定义的联合类型
可选元组类型
let x:[string,number,boolean?];x = ['hi',1234];
声明
interface没法用declare的args...declare function test(...args:[number,string,boolean]):void;相当于declare function test(arg1:number,arg2:string,arg3:boolean):void;
不限制长度举例
let str:[string,...number[]] = ['123',1,2,3];
