typescript2
数组类型注解
let numberList: number[] = [1, 2, 3]
let stringList: string[] = ['好的呀', '是的呢', '什么呢']
let undefinedList: undefined[] = [undefined, undefined, undefined]
let arr: (number | string)[] = ['1', 2, '3', 4, '5']
class Jiejie {
constructor() {
this.name = '';
this.age = 0
}
name: string;
age: number;
}
const xiaojiejie: Jiejie[] = [
{
name: '超杰',
age: 27
}
]
console.log('xiaojiejie', xiaojiejie);
元组
const yuanList: [string, string, number] = ['111', '222', 20]
const csvList: [string, string, number][] = [
['111', '2222', 20],
['222', '3333', 40],
['555', '6666', 60]
]