Skip to content

Commit b2f0543

Browse files
committed
Add tests
1 parent adeafcc commit b2f0543

File tree

4 files changed

+534
-0
lines changed

4 files changed

+534
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
tests/cases/conformance/types/tuple/contextualTypeTupleEnd.ts(8,1): error TS2345: Argument of type '[]' is not assignable to parameter of type '[...((arg: number) => void)[], (arg: string) => void]'.
2+
Source has 0 element(s) but target requires 1.
3+
tests/cases/conformance/types/tuple/contextualTypeTupleEnd.ts(13,7): error TS2322: Type '[]' is not assignable to type 'Funcs'.
4+
Source has 0 element(s) but target requires 1.
5+
tests/cases/conformance/types/tuple/contextualTypeTupleEnd.ts(43,12): error TS2339: Property 'foo' does not exist on type 'number'.
6+
tests/cases/conformance/types/tuple/contextualTypeTupleEnd.ts(44,12): error TS2339: Property 'bar' does not exist on type 'number'.
7+
8+
9+
==== tests/cases/conformance/types/tuple/contextualTypeTupleEnd.ts (4 errors) ====
10+
type Funcs = [...((arg: number) => void)[], (arg: string) => void];
11+
12+
declare function num(x: number): void;
13+
declare function str(x: string): void;
14+
15+
declare function f1(...args: Funcs): void;
16+
17+
f1(); // Error
18+
~~~~
19+
!!! error TS2345: Argument of type '[]' is not assignable to parameter of type '[...((arg: number) => void)[], (arg: string) => void]'.
20+
!!! error TS2345: Source has 0 element(s) but target requires 1.
21+
f1(x => str(x));
22+
f1(x => num(x), x => str(x));
23+
f1(x => num(x), x => num(x), x => str(x));
24+
25+
const a0: Funcs = []; // Error
26+
~~
27+
!!! error TS2322: Type '[]' is not assignable to type 'Funcs'.
28+
!!! error TS2322: Source has 0 element(s) but target requires 1.
29+
const a1: Funcs = [x => str(x)];
30+
const a2: Funcs = [x => num(x), x => str(x)];
31+
const a3: Funcs = [x => num(x), x => num(x), x => str(x)];
32+
33+
// Repro from #43122
34+
35+
export type Selector<State> = (state: State) => unknown;
36+
export type SelectorTuple<State> = Selector<State>[];
37+
38+
export type ExampleState = {
39+
foo: "foo";
40+
bar: 42;
41+
};
42+
43+
export function createSelector<S extends SelectorTuple<ExampleState>>(...selectors: [...selectors: S, f: (x: any) => any]) {
44+
console.log(selectors);
45+
}
46+
47+
createSelector(
48+
x => x.foo,
49+
x => x.bar,
50+
() => 42
51+
);
52+
53+
// Repro from #43122
54+
55+
declare function example(...args: [...((n: number) => void)[], (x: any) => void]): void
56+
57+
example(
58+
x => x.foo, // Error
59+
~~~
60+
!!! error TS2339: Property 'foo' does not exist on type 'number'.
61+
x => x.bar, // Error
62+
~~~
63+
!!! error TS2339: Property 'bar' does not exist on type 'number'.
64+
x => x.baz,
65+
);
66+
67+
// Repro from #52846
68+
69+
declare function test(...args: [...((arg: number) => void)[], (arg: string) => void]): void;
70+
71+
test(a => a, b => b, c => c);
72+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
=== tests/cases/conformance/types/tuple/contextualTypeTupleEnd.ts ===
2+
type Funcs = [...((arg: number) => void)[], (arg: string) => void];
3+
>Funcs : Symbol(Funcs, Decl(contextualTypeTupleEnd.ts, 0, 0))
4+
>arg : Symbol(arg, Decl(contextualTypeTupleEnd.ts, 0, 19))
5+
>arg : Symbol(arg, Decl(contextualTypeTupleEnd.ts, 0, 45))
6+
7+
declare function num(x: number): void;
8+
>num : Symbol(num, Decl(contextualTypeTupleEnd.ts, 0, 67))
9+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 2, 21))
10+
11+
declare function str(x: string): void;
12+
>str : Symbol(str, Decl(contextualTypeTupleEnd.ts, 2, 38))
13+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 3, 21))
14+
15+
declare function f1(...args: Funcs): void;
16+
>f1 : Symbol(f1, Decl(contextualTypeTupleEnd.ts, 3, 38))
17+
>args : Symbol(args, Decl(contextualTypeTupleEnd.ts, 5, 20))
18+
>Funcs : Symbol(Funcs, Decl(contextualTypeTupleEnd.ts, 0, 0))
19+
20+
f1(); // Error
21+
>f1 : Symbol(f1, Decl(contextualTypeTupleEnd.ts, 3, 38))
22+
23+
f1(x => str(x));
24+
>f1 : Symbol(f1, Decl(contextualTypeTupleEnd.ts, 3, 38))
25+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 8, 3))
26+
>str : Symbol(str, Decl(contextualTypeTupleEnd.ts, 2, 38))
27+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 8, 3))
28+
29+
f1(x => num(x), x => str(x));
30+
>f1 : Symbol(f1, Decl(contextualTypeTupleEnd.ts, 3, 38))
31+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 9, 3))
32+
>num : Symbol(num, Decl(contextualTypeTupleEnd.ts, 0, 67))
33+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 9, 3))
34+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 9, 15))
35+
>str : Symbol(str, Decl(contextualTypeTupleEnd.ts, 2, 38))
36+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 9, 15))
37+
38+
f1(x => num(x), x => num(x), x => str(x));
39+
>f1 : Symbol(f1, Decl(contextualTypeTupleEnd.ts, 3, 38))
40+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 10, 3))
41+
>num : Symbol(num, Decl(contextualTypeTupleEnd.ts, 0, 67))
42+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 10, 3))
43+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 10, 15))
44+
>num : Symbol(num, Decl(contextualTypeTupleEnd.ts, 0, 67))
45+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 10, 15))
46+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 10, 28))
47+
>str : Symbol(str, Decl(contextualTypeTupleEnd.ts, 2, 38))
48+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 10, 28))
49+
50+
const a0: Funcs = []; // Error
51+
>a0 : Symbol(a0, Decl(contextualTypeTupleEnd.ts, 12, 5))
52+
>Funcs : Symbol(Funcs, Decl(contextualTypeTupleEnd.ts, 0, 0))
53+
54+
const a1: Funcs = [x => str(x)];
55+
>a1 : Symbol(a1, Decl(contextualTypeTupleEnd.ts, 13, 5))
56+
>Funcs : Symbol(Funcs, Decl(contextualTypeTupleEnd.ts, 0, 0))
57+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 13, 19))
58+
>str : Symbol(str, Decl(contextualTypeTupleEnd.ts, 2, 38))
59+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 13, 19))
60+
61+
const a2: Funcs = [x => num(x), x => str(x)];
62+
>a2 : Symbol(a2, Decl(contextualTypeTupleEnd.ts, 14, 5))
63+
>Funcs : Symbol(Funcs, Decl(contextualTypeTupleEnd.ts, 0, 0))
64+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 14, 19))
65+
>num : Symbol(num, Decl(contextualTypeTupleEnd.ts, 0, 67))
66+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 14, 19))
67+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 14, 31))
68+
>str : Symbol(str, Decl(contextualTypeTupleEnd.ts, 2, 38))
69+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 14, 31))
70+
71+
const a3: Funcs = [x => num(x), x => num(x), x => str(x)];
72+
>a3 : Symbol(a3, Decl(contextualTypeTupleEnd.ts, 15, 5))
73+
>Funcs : Symbol(Funcs, Decl(contextualTypeTupleEnd.ts, 0, 0))
74+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 15, 19))
75+
>num : Symbol(num, Decl(contextualTypeTupleEnd.ts, 0, 67))
76+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 15, 19))
77+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 15, 31))
78+
>num : Symbol(num, Decl(contextualTypeTupleEnd.ts, 0, 67))
79+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 15, 31))
80+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 15, 44))
81+
>str : Symbol(str, Decl(contextualTypeTupleEnd.ts, 2, 38))
82+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 15, 44))
83+
84+
// Repro from #43122
85+
86+
export type Selector<State> = (state: State) => unknown;
87+
>Selector : Symbol(Selector, Decl(contextualTypeTupleEnd.ts, 15, 58))
88+
>State : Symbol(State, Decl(contextualTypeTupleEnd.ts, 19, 21))
89+
>state : Symbol(state, Decl(contextualTypeTupleEnd.ts, 19, 31))
90+
>State : Symbol(State, Decl(contextualTypeTupleEnd.ts, 19, 21))
91+
92+
export type SelectorTuple<State> = Selector<State>[];
93+
>SelectorTuple : Symbol(SelectorTuple, Decl(contextualTypeTupleEnd.ts, 19, 56))
94+
>State : Symbol(State, Decl(contextualTypeTupleEnd.ts, 20, 26))
95+
>Selector : Symbol(Selector, Decl(contextualTypeTupleEnd.ts, 15, 58))
96+
>State : Symbol(State, Decl(contextualTypeTupleEnd.ts, 20, 26))
97+
98+
export type ExampleState = {
99+
>ExampleState : Symbol(ExampleState, Decl(contextualTypeTupleEnd.ts, 20, 53))
100+
101+
foo: "foo";
102+
>foo : Symbol(foo, Decl(contextualTypeTupleEnd.ts, 22, 28))
103+
104+
bar: 42;
105+
>bar : Symbol(bar, Decl(contextualTypeTupleEnd.ts, 23, 15))
106+
107+
};
108+
109+
export function createSelector<S extends SelectorTuple<ExampleState>>(...selectors: [...selectors: S, f: (x: any) => any]) {
110+
>createSelector : Symbol(createSelector, Decl(contextualTypeTupleEnd.ts, 25, 2))
111+
>S : Symbol(S, Decl(contextualTypeTupleEnd.ts, 27, 31))
112+
>SelectorTuple : Symbol(SelectorTuple, Decl(contextualTypeTupleEnd.ts, 19, 56))
113+
>ExampleState : Symbol(ExampleState, Decl(contextualTypeTupleEnd.ts, 20, 53))
114+
>selectors : Symbol(selectors, Decl(contextualTypeTupleEnd.ts, 27, 70))
115+
>S : Symbol(S, Decl(contextualTypeTupleEnd.ts, 27, 31))
116+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 27, 106))
117+
118+
console.log(selectors);
119+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
120+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
121+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
122+
>selectors : Symbol(selectors, Decl(contextualTypeTupleEnd.ts, 27, 70))
123+
}
124+
125+
createSelector(
126+
>createSelector : Symbol(createSelector, Decl(contextualTypeTupleEnd.ts, 25, 2))
127+
128+
x => x.foo,
129+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 31, 15))
130+
>x.foo : Symbol(foo, Decl(contextualTypeTupleEnd.ts, 22, 28))
131+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 31, 15))
132+
>foo : Symbol(foo, Decl(contextualTypeTupleEnd.ts, 22, 28))
133+
134+
x => x.bar,
135+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 32, 15))
136+
>x.bar : Symbol(bar, Decl(contextualTypeTupleEnd.ts, 23, 15))
137+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 32, 15))
138+
>bar : Symbol(bar, Decl(contextualTypeTupleEnd.ts, 23, 15))
139+
140+
() => 42
141+
);
142+
143+
// Repro from #43122
144+
145+
declare function example(...args: [...((n: number) => void)[], (x: any) => void]): void
146+
>example : Symbol(example, Decl(contextualTypeTupleEnd.ts, 35, 2))
147+
>args : Symbol(args, Decl(contextualTypeTupleEnd.ts, 39, 25))
148+
>n : Symbol(n, Decl(contextualTypeTupleEnd.ts, 39, 40))
149+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 39, 64))
150+
151+
example(
152+
>example : Symbol(example, Decl(contextualTypeTupleEnd.ts, 35, 2))
153+
154+
x => x.foo, // Error
155+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 41, 8))
156+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 41, 8))
157+
158+
x => x.bar, // Error
159+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 42, 15))
160+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 42, 15))
161+
162+
x => x.baz,
163+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 43, 15))
164+
>x : Symbol(x, Decl(contextualTypeTupleEnd.ts, 43, 15))
165+
166+
);
167+
168+
// Repro from #52846
169+
170+
declare function test(...args: [...((arg: number) => void)[], (arg: string) => void]): void;
171+
>test : Symbol(test, Decl(contextualTypeTupleEnd.ts, 45, 2))
172+
>args : Symbol(args, Decl(contextualTypeTupleEnd.ts, 49, 22))
173+
>arg : Symbol(arg, Decl(contextualTypeTupleEnd.ts, 49, 37))
174+
>arg : Symbol(arg, Decl(contextualTypeTupleEnd.ts, 49, 63))
175+
176+
test(a => a, b => b, c => c);
177+
>test : Symbol(test, Decl(contextualTypeTupleEnd.ts, 45, 2))
178+
>a : Symbol(a, Decl(contextualTypeTupleEnd.ts, 51, 5))
179+
>a : Symbol(a, Decl(contextualTypeTupleEnd.ts, 51, 5))
180+
>b : Symbol(b, Decl(contextualTypeTupleEnd.ts, 51, 12))
181+
>b : Symbol(b, Decl(contextualTypeTupleEnd.ts, 51, 12))
182+
>c : Symbol(c, Decl(contextualTypeTupleEnd.ts, 51, 20))
183+
>c : Symbol(c, Decl(contextualTypeTupleEnd.ts, 51, 20))
184+

0 commit comments

Comments
 (0)