1/*
2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16function foo(x, y, z) {
17  console.log(x, y, z);
18}
19
20const args: [number, string, boolean] = [0, 'str', false];
21foo(...args);
22
23function bar(x, y, ...z) {
24  console.log(x, y, z);
25}
26
27bar(-1, 0, ...args);
28
29let arr: number[] = [ 1, 2, 3 ];
30bar(-1, 0, ...arr);
31
32function foo2(n:number, ...rest: number[]) {
33
34  rest.values
35}
36function foo3(...rest: bigint[]) {}
37
38let a1 = [0,1]
39let a2 = [1,2,3,4,5]
40let a3: number[] = [1,2,3,4,5]
41let a4: Array<number> = [1,2,3,4,5]
42let a5 = new Array(10)
43let a6 = new Int8Array(10)
44let a7 = new Uint8Array(10)
45let a8 = new Uint8ClampedArray(10)
46let a9 = new Int16Array(10)
47let a10 = new Uint16Array(10)
48let a11 = new Int32Array(10)
49let a12 = new Uint32Array(10)
50let a13 = new Float32Array(10)
51let a14 = new Float64Array(10)
52let a15 = new BigInt64Array(10)
53let a16 = new BigUint64Array(10)
54
55foo2(1, ...a1)
56foo2(1, ...a2)
57foo2(1, ...a3)
58foo2(1, ...a4)
59foo2(1, ...a5)
60foo2(1, ...a6)
61foo2(1, ...a7)
62foo2(1, ...a8)
63foo2(1, ...a9)
64foo2(1, ...a10)
65foo2(1, ...a11)
66foo2(1, ...a12)
67foo2(1, ...a13)
68foo2(1, ...a14)
69foo3(...a15)
70foo3(...a16)
71
72function fUnionArr(...a: (number | string)[]) {}
73let x: (number | string)[] = [];
74let y = [1, 'string', 10]
75let z: [number, string, number] = [1, 'string', 10]
76
77fUnionArr(...x);
78/**
79 * OK, spec 7.5.2 Type inference from Types of Elements
80 * type is (number | string)[], it is inferred from types of the elements. 
81 */
82fUnionArr(...y);
83/**
84 * NOT OK
85 * type is explicitly specified to be tuple
86 */
87fUnionArr(...z);
88