Skip to content

Commit 9ba0668

Browse files
committed
Test:spread array after required params
1 parent 26416c3 commit 9ba0668

File tree

3 files changed

+222
-0
lines changed

3 files changed

+222
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(40,5): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
2+
Type 'string' is not assignable to type 'number'.
3+
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(41,5): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
4+
Type 'string' is not assignable to type 'number'.
5+
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(42,13): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
6+
Type 'string' is not assignable to type 'number'.
7+
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(43,13): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
8+
Type 'string' is not assignable to type 'number'.
9+
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(44,11): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
10+
Type 'string' is not assignable to type 'number'.
11+
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(45,11): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
12+
Type 'string' is not assignable to type 'number'.
13+
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(46,1): error TS2346: Supplied parameters do not match any signature of call target.
14+
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(46,11): error TS2461: Type '(a?: number, b?: number) => void' is not an array type.
15+
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(47,1): error TS2346: Supplied parameters do not match any signature of call target.
16+
tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts(48,1): error TS2346: Supplied parameters do not match any signature of call target.
17+
18+
19+
==== tests/cases/conformance/expressions/functionCalls/callWithSpread2.ts (10 errors) ====
20+
// Desired semantics: take type of array that is spread,
21+
// allow it to be applied to a
22+
// *trailing* set of optional parameters whose types match.
23+
// Length is *not* checked, the parameters it's applied to just have to be optional.
24+
25+
// that means that tuples are non-starters because their array element type
26+
// is a union like string | number.
27+
28+
// with exceptions for JS functions that use arguments, or maybe all JS functions
29+
30+
declare function all(a?: number, b?: number): void;
31+
declare function weird(a?: number | string, b?: number | string): void;
32+
declare function prefix(s: string, a?: number, b?: number): void;
33+
declare function rest(s: string, a?: number, b?: number, ...rest: number[]): void;
34+
declare function normal(s: string): void;
35+
declare function thunk(): string;
36+
37+
declare var ns: number[];
38+
declare var mixed: (number | string)[];
39+
declare var tuple: [number, string];
40+
41+
// good
42+
all(...ns)
43+
weird(...ns)
44+
weird(...mixed)
45+
weird(...tuple)
46+
prefix("a", ...ns)
47+
rest("d", ...ns)
48+
49+
50+
// this covers the arguments case
51+
normal("g", ...ns)
52+
normal("h", ...mixed)
53+
normal("i", ...tuple)
54+
thunk(...ns)
55+
thunk(...mixed)
56+
thunk(...tuple)
57+
58+
// bad
59+
all(...mixed)
60+
~~~~~~~~
61+
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
62+
!!! error TS2345: Type 'string' is not assignable to type 'number'.
63+
all(...tuple)
64+
~~~~~~~~
65+
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
66+
!!! error TS2345: Type 'string' is not assignable to type 'number'.
67+
prefix("b", ...mixed)
68+
~~~~~~~~
69+
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
70+
!!! error TS2345: Type 'string' is not assignable to type 'number'.
71+
prefix("c", ...tuple)
72+
~~~~~~~~
73+
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
74+
!!! error TS2345: Type 'string' is not assignable to type 'number'.
75+
rest("e", ...mixed)
76+
~~~~~~~~
77+
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
78+
!!! error TS2345: Type 'string' is not assignable to type 'number'.
79+
rest("f", ...tuple)
80+
~~~~~~~~
81+
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'number'.
82+
!!! error TS2345: Type 'string' is not assignable to type 'number'.
83+
prefix(...all) // required parameters are required
84+
~~~~~~~~~~~~~~
85+
!!! error TS2346: Supplied parameters do not match any signature of call target.
86+
~~~
87+
!!! error TS2461: Type '(a?: number, b?: number) => void' is not an array type.
88+
prefix(...mixed)
89+
~~~~~~~~~~~~~~~~
90+
!!! error TS2346: Supplied parameters do not match any signature of call target.
91+
prefix(...tuple)
92+
~~~~~~~~~~~~~~~~
93+
!!! error TS2346: Supplied parameters do not match any signature of call target.
94+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//// [callWithSpread2.ts]
2+
// Desired semantics: take type of array that is spread,
3+
// allow it to be applied to a
4+
// *trailing* set of optional parameters whose types match.
5+
// Length is *not* checked, the parameters it's applied to just have to be optional.
6+
7+
// that means that tuples are non-starters because their array element type
8+
// is a union like string | number.
9+
10+
// with exceptions for JS functions that use arguments, or maybe all JS functions
11+
12+
declare function all(a?: number, b?: number): void;
13+
declare function weird(a?: number | string, b?: number | string): void;
14+
declare function prefix(s: string, a?: number, b?: number): void;
15+
declare function rest(s: string, a?: number, b?: number, ...rest: number[]): void;
16+
declare function normal(s: string): void;
17+
declare function thunk(): string;
18+
19+
declare var ns: number[];
20+
declare var mixed: (number | string)[];
21+
declare var tuple: [number, string];
22+
23+
// good
24+
all(...ns)
25+
weird(...ns)
26+
weird(...mixed)
27+
weird(...tuple)
28+
prefix("a", ...ns)
29+
rest("d", ...ns)
30+
31+
32+
// this covers the arguments case
33+
normal("g", ...ns)
34+
normal("h", ...mixed)
35+
normal("i", ...tuple)
36+
thunk(...ns)
37+
thunk(...mixed)
38+
thunk(...tuple)
39+
40+
// bad
41+
all(...mixed)
42+
all(...tuple)
43+
prefix("b", ...mixed)
44+
prefix("c", ...tuple)
45+
rest("e", ...mixed)
46+
rest("f", ...tuple)
47+
prefix(...all) // required parameters are required
48+
prefix(...mixed)
49+
prefix(...tuple)
50+
51+
52+
//// [callWithSpread2.js]
53+
// Desired semantics: take type of array that is spread,
54+
// allow it to be applied to a
55+
// *trailing* set of optional parameters whose types match.
56+
// Length is *not* checked, the parameters it's applied to just have to be optional.
57+
// good
58+
all.apply(void 0, ns);
59+
weird.apply(void 0, ns);
60+
weird.apply(void 0, mixed);
61+
weird.apply(void 0, tuple);
62+
prefix.apply(void 0, ["a"].concat(ns));
63+
rest.apply(void 0, ["d"].concat(ns));
64+
// this covers the arguments case
65+
normal.apply(void 0, ["g"].concat(ns));
66+
normal.apply(void 0, ["h"].concat(mixed));
67+
normal.apply(void 0, ["i"].concat(tuple));
68+
thunk.apply(void 0, ns);
69+
thunk.apply(void 0, mixed);
70+
thunk.apply(void 0, tuple);
71+
// bad
72+
all.apply(void 0, mixed);
73+
all.apply(void 0, tuple);
74+
prefix.apply(void 0, ["b"].concat(mixed));
75+
prefix.apply(void 0, ["c"].concat(tuple));
76+
rest.apply(void 0, ["e"].concat(mixed));
77+
rest.apply(void 0, ["f"].concat(tuple));
78+
prefix.apply(void 0, all); // required parameters are required
79+
prefix.apply(void 0, mixed);
80+
prefix.apply(void 0, tuple);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Desired semantics: take type of array that is spread,
2+
// allow it to be applied to a
3+
// *trailing* set of optional parameters whose types match.
4+
// Length is *not* checked, the parameters it's applied to just have to be optional.
5+
6+
// that means that tuples are non-starters because their array element type
7+
// is a union like string | number.
8+
9+
// with exceptions for JS functions that use arguments, or maybe all JS functions
10+
11+
declare function all(a?: number, b?: number): void;
12+
declare function weird(a?: number | string, b?: number | string): void;
13+
declare function prefix(s: string, a?: number, b?: number): void;
14+
declare function rest(s: string, a?: number, b?: number, ...rest: number[]): void;
15+
declare function normal(s: string): void;
16+
declare function thunk(): string;
17+
18+
declare var ns: number[];
19+
declare var mixed: (number | string)[];
20+
declare var tuple: [number, string];
21+
22+
// good
23+
all(...ns)
24+
weird(...ns)
25+
weird(...mixed)
26+
weird(...tuple)
27+
prefix("a", ...ns)
28+
rest("d", ...ns)
29+
30+
31+
// this covers the arguments case
32+
normal("g", ...ns)
33+
normal("h", ...mixed)
34+
normal("i", ...tuple)
35+
thunk(...ns)
36+
thunk(...mixed)
37+
thunk(...tuple)
38+
39+
// bad
40+
all(...mixed)
41+
all(...tuple)
42+
prefix("b", ...mixed)
43+
prefix("c", ...tuple)
44+
rest("e", ...mixed)
45+
rest("f", ...tuple)
46+
prefix(...all) // required parameters are required
47+
prefix(...mixed)
48+
prefix(...tuple)

0 commit comments

Comments
 (0)