# 数组
# 搭配接口
interface IStudents {
name: string;
gender: boolean;
}
let people: Array<IStudents> = [
{ name: "alice", gender: false },
{ name: "Bob", gender: true }
];
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 类数组
事实上常用的类数组都有自己的接口定义,如 IArguments
, NodeList
, HTMLCollection
等:
function sum(a, b, c) {
let sum: number = 0;
let args: IArguments = arguments;
for (let i: number = 0; i < args.length; i++) {
sum += args[i];
}
return sum;
}
const res: number = sum(1, 2, 3);
console.log(res); //6
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11