object generic
Array
Array
1 2 3
| const arr:string[] = ["foo"]; const arr1:Array<string> = ["foo"];
|
ReadonlyArray
not changed
1
| const arr: ReadonlyArray<string> = [];
|
Tuple
No changed length and type
1 2 3 4 5 6
| let arr1: StringorNumber = ["foo", 1];
arr1[2] = 1; const arr1Index2 = arr1[2]; arr1.push("foo2");
|
Destruture Tuple
1 2 3 4 5
| function doSomething(stringHash: [string, number]) { const [inputString, hash] = stringHash; console.log(inputString); console.log(hash); }
|
Optional tuple elements
Rest elements
1 2 3 4
| function readButtonInput(...args: [string, number, ...boolean[]]) { const [name, version, ...input] = args; } readButtonInput()
|
Readonly Tuple
no changed
1 2 3 4
| function doSomething(pair: readonly [string, number]) { pair[0] = "hello!"; }
|
越界元素