1、普通类型[]
let arr:number[] = [1,2,3,4] //数字类型
let arrStr:string[] = ['1','2'] //字符串类型
let arrAny:any[] = [1,'2',true,[],{}] //任意类型
2、泛型
let arr:Array<number> = [1,2,3,4] //数字类型
let arrStr:Array<string> = ['1','2'] //字符串类型
let arrAny:Array<any> = [1,'2',true,[],{}] //任意类型
3、多维数组
let arr :number[][] = [[1,3],[5,6]]
let arr2:Array<Array<number|string>> = [[1,3],[5,6,'aa']]
4、arguments数组
function Arr(...args: any): void {
console.log(arguments)
let num: IArguments = arguments //ts内置对象IArguments 定义
}
Arr(1, 2, 3)
//其中 IArguments 是 TypeScript 中定义好了的类型,它实际上就是:
interface IArguments {
[index: number]: any;
length: number;
callee: Function;
}