let list1: (number)[] = [1, 2, 3];
list1.push(5);
console.log('list1', list1); // list1 [ 1, 2, 3, 5 ]
let list2: (number | string)[] = [1, 2, 3, '3'];
console.log('list2', list2); // list2 [ 1, 2, 3, '3' ]
let list3: Array<number> = [1, 2, 3];
console.log('list3', list3); // list3 [ 1, 2, 3 ]
let list4: Array<number | string> = [1, 2, 3, '4'];
console.log('list4', list4); // list4 [ 1, 2, 3, '4' ]
interface List5 {
[index: number]: number
}
let list5: List5 = [1, 2, 3, 4, 5];
console.log('list5', list5); // list5 [ 1, 2, 3, 4, 5 ]
interface List6 {
[index: number]: number | string
}
let list6: List6 = [1, 2, 3, 4, 5, '6'];
console.log('list6', list6); // list6 [ 1, 2, 3, 4, 5, '6' ]
const list7: [string, number] = ['1', 2];
console.log('list7', list7); // list7 [ '1', 2 ]
function test() {
// IArguments:这个是ts内部定义好的interface接口
/*
在IArguments身上按住ctrl + 鼠标左键可以看到:
interface IArguments {
[Symbol.iterator](): IterableIterator;
}
*/
let args: IArguments = arguments;
}
test();
interface Args {
// 方式一:
// [Symbol.iterator](): IterableIterator;
// 方式二:
[index: number]: any;
length: number;
callee: Function;
}
function test1() {
let args: Args = arguments
}
test1();