Skip to content

Commit 201c263

Browse files
committed
Update one test, add another.
1 parent ca33f40 commit 201c263

5 files changed

+384
-8
lines changed

tests/baselines/reference/checkJsxGenericTagHasCorrectInferences.errors.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
tests/cases/conformance/jsx/file.tsx(13,54): error TS2322: Type '(a: { x: string; }) => string' is not assignable to type '((a: { x: string; }) => string) & ((cur: { x: string; }) => { x: string; })'.
2-
Type '(a: { x: string; }) => string' is not assignable to type '(cur: { x: string; }) => { x: string; }'.
3-
Type 'string' is not assignable to type '{ x: string; }'.
1+
tests/cases/conformance/jsx/file.tsx(13,71): error TS2322: Type 'string' is not assignable to type 'string & { x: string; }'.
2+
Type 'string' is not assignable to type '{ x: string; }'.
43

54

65
==== tests/cases/conformance/jsx/file.tsx (1 errors) ====
@@ -17,8 +16,6 @@ tests/cases/conformance/jsx/file.tsx(13,54): error TS2322: Type '(a: { x: string
1716
let b = <GenericComponent initialValues={12} nextValues={a => a} />; // No error - Values should be reinstantiated with `number` (since `object` is a default, not a constraint)
1817
let c = <GenericComponent initialValues={{ x: "y" }} nextValues={a => ({ x: a.x })} />; // No Error
1918
let d = <GenericComponent initialValues={{ x: "y" }} nextValues={a => a.x} />; // Error - `string` is not assignable to `{x: string}`
20-
~~~~~~~~~~
21-
!!! error TS2322: Type '(a: { x: string; }) => string' is not assignable to type '((a: { x: string; }) => string) & ((cur: { x: string; }) => { x: string; })'.
22-
!!! error TS2322: Type '(a: { x: string; }) => string' is not assignable to type '(cur: { x: string; }) => { x: string; }'.
23-
!!! error TS2322: Type 'string' is not assignable to type '{ x: string; }'.
24-
!!! related TS6500 tests/cases/conformance/jsx/file.tsx:13:54: The expected type comes from property 'nextValues' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<GenericComponent<{ initialValues: { x: string; }; nextValues: (a: { x: string; }) => string; }, { x: string; }>> & { initialValues: { x: string; }; nextValues: (a: { x: string; }) => string; } & BaseProps<{ x: string; }> & { children?: ReactNode; }'
19+
~~~
20+
!!! error TS2322: Type 'string' is not assignable to type 'string & { x: string; }'.
21+
!!! error TS2322: Type 'string' is not assignable to type '{ x: string; }'.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//// [intersectionOfCallsWithSameParameters.ts]
2+
interface One {
3+
overload(id: string): { one: number };
4+
intersect(id: string): { one: number };
5+
}
6+
7+
interface Two {
8+
overload(id: number): { two: number };
9+
intersect(id: string): { two: number };
10+
}
11+
12+
class Both implements One, Two {
13+
overload(id: number): { two: number };
14+
overload(id: string): { one: number };
15+
overload(id: string | number): { one: number, two: number } {
16+
return {
17+
one: 1,
18+
two: 2
19+
};
20+
}
21+
22+
intersect(id: string): { one: number, two: number } {
23+
return {
24+
one: 1,
25+
two: 2
26+
};
27+
}
28+
}
29+
30+
const b = new Both();
31+
const intersect: { one: number, two: number } = b.intersect('test');
32+
const overloadA: { one: number } = b.overload('test');
33+
const overloadB: { two: number } = b.overload(4);
34+
const bAs: One & Two = b;
35+
const asIntersect: { one: number, two: number } = bAs.intersect('test');
36+
const asOverloadA: { one: number } = bAs.overload('test');
37+
const asOverloadB: { two: number } = bAs.overload(4);
38+
39+
40+
//// [intersectionOfCallsWithSameParameters.js]
41+
"use strict";
42+
var Both = /** @class */ (function () {
43+
function Both() {
44+
}
45+
Both.prototype.overload = function (id) {
46+
return {
47+
one: 1,
48+
two: 2
49+
};
50+
};
51+
Both.prototype.intersect = function (id) {
52+
return {
53+
one: 1,
54+
two: 2
55+
};
56+
};
57+
return Both;
58+
}());
59+
var b = new Both();
60+
var intersect = b.intersect('test');
61+
var overloadA = b.overload('test');
62+
var overloadB = b.overload(4);
63+
var bAs = b;
64+
var asIntersect = bAs.intersect('test');
65+
var asOverloadA = bAs.overload('test');
66+
var asOverloadB = bAs.overload(4);
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
=== tests/cases/compiler/intersectionOfCallsWithSameParameters.ts ===
2+
interface One {
3+
>One : Symbol(One, Decl(intersectionOfCallsWithSameParameters.ts, 0, 0))
4+
5+
overload(id: string): { one: number };
6+
>overload : Symbol(One.overload, Decl(intersectionOfCallsWithSameParameters.ts, 0, 15))
7+
>id : Symbol(id, Decl(intersectionOfCallsWithSameParameters.ts, 1, 13))
8+
>one : Symbol(one, Decl(intersectionOfCallsWithSameParameters.ts, 1, 27))
9+
10+
intersect(id: string): { one: number };
11+
>intersect : Symbol(One.intersect, Decl(intersectionOfCallsWithSameParameters.ts, 1, 42))
12+
>id : Symbol(id, Decl(intersectionOfCallsWithSameParameters.ts, 2, 14))
13+
>one : Symbol(one, Decl(intersectionOfCallsWithSameParameters.ts, 2, 28))
14+
}
15+
16+
interface Two {
17+
>Two : Symbol(Two, Decl(intersectionOfCallsWithSameParameters.ts, 3, 1))
18+
19+
overload(id: number): { two: number };
20+
>overload : Symbol(Two.overload, Decl(intersectionOfCallsWithSameParameters.ts, 5, 15))
21+
>id : Symbol(id, Decl(intersectionOfCallsWithSameParameters.ts, 6, 13))
22+
>two : Symbol(two, Decl(intersectionOfCallsWithSameParameters.ts, 6, 27))
23+
24+
intersect(id: string): { two: number };
25+
>intersect : Symbol(Two.intersect, Decl(intersectionOfCallsWithSameParameters.ts, 6, 42))
26+
>id : Symbol(id, Decl(intersectionOfCallsWithSameParameters.ts, 7, 14))
27+
>two : Symbol(two, Decl(intersectionOfCallsWithSameParameters.ts, 7, 28))
28+
}
29+
30+
class Both implements One, Two {
31+
>Both : Symbol(Both, Decl(intersectionOfCallsWithSameParameters.ts, 8, 1))
32+
>One : Symbol(One, Decl(intersectionOfCallsWithSameParameters.ts, 0, 0))
33+
>Two : Symbol(Two, Decl(intersectionOfCallsWithSameParameters.ts, 3, 1))
34+
35+
overload(id: number): { two: number };
36+
>overload : Symbol(Both.overload, Decl(intersectionOfCallsWithSameParameters.ts, 10, 32), Decl(intersectionOfCallsWithSameParameters.ts, 11, 42), Decl(intersectionOfCallsWithSameParameters.ts, 12, 42))
37+
>id : Symbol(id, Decl(intersectionOfCallsWithSameParameters.ts, 11, 13))
38+
>two : Symbol(two, Decl(intersectionOfCallsWithSameParameters.ts, 11, 27))
39+
40+
overload(id: string): { one: number };
41+
>overload : Symbol(Both.overload, Decl(intersectionOfCallsWithSameParameters.ts, 10, 32), Decl(intersectionOfCallsWithSameParameters.ts, 11, 42), Decl(intersectionOfCallsWithSameParameters.ts, 12, 42))
42+
>id : Symbol(id, Decl(intersectionOfCallsWithSameParameters.ts, 12, 13))
43+
>one : Symbol(one, Decl(intersectionOfCallsWithSameParameters.ts, 12, 27))
44+
45+
overload(id: string | number): { one: number, two: number } {
46+
>overload : Symbol(Both.overload, Decl(intersectionOfCallsWithSameParameters.ts, 10, 32), Decl(intersectionOfCallsWithSameParameters.ts, 11, 42), Decl(intersectionOfCallsWithSameParameters.ts, 12, 42))
47+
>id : Symbol(id, Decl(intersectionOfCallsWithSameParameters.ts, 13, 13))
48+
>one : Symbol(one, Decl(intersectionOfCallsWithSameParameters.ts, 13, 36))
49+
>two : Symbol(two, Decl(intersectionOfCallsWithSameParameters.ts, 13, 49))
50+
51+
return {
52+
one: 1,
53+
>one : Symbol(one, Decl(intersectionOfCallsWithSameParameters.ts, 14, 16))
54+
55+
two: 2
56+
>two : Symbol(two, Decl(intersectionOfCallsWithSameParameters.ts, 15, 19))
57+
58+
};
59+
}
60+
61+
intersect(id: string): { one: number, two: number } {
62+
>intersect : Symbol(Both.intersect, Decl(intersectionOfCallsWithSameParameters.ts, 18, 5))
63+
>id : Symbol(id, Decl(intersectionOfCallsWithSameParameters.ts, 20, 14))
64+
>one : Symbol(one, Decl(intersectionOfCallsWithSameParameters.ts, 20, 28))
65+
>two : Symbol(two, Decl(intersectionOfCallsWithSameParameters.ts, 20, 41))
66+
67+
return {
68+
one: 1,
69+
>one : Symbol(one, Decl(intersectionOfCallsWithSameParameters.ts, 21, 16))
70+
71+
two: 2
72+
>two : Symbol(two, Decl(intersectionOfCallsWithSameParameters.ts, 22, 19))
73+
74+
};
75+
}
76+
}
77+
78+
const b = new Both();
79+
>b : Symbol(b, Decl(intersectionOfCallsWithSameParameters.ts, 28, 5))
80+
>Both : Symbol(Both, Decl(intersectionOfCallsWithSameParameters.ts, 8, 1))
81+
82+
const intersect: { one: number, two: number } = b.intersect('test');
83+
>intersect : Symbol(intersect, Decl(intersectionOfCallsWithSameParameters.ts, 29, 5))
84+
>one : Symbol(one, Decl(intersectionOfCallsWithSameParameters.ts, 29, 18))
85+
>two : Symbol(two, Decl(intersectionOfCallsWithSameParameters.ts, 29, 31))
86+
>b.intersect : Symbol(Both.intersect, Decl(intersectionOfCallsWithSameParameters.ts, 18, 5))
87+
>b : Symbol(b, Decl(intersectionOfCallsWithSameParameters.ts, 28, 5))
88+
>intersect : Symbol(Both.intersect, Decl(intersectionOfCallsWithSameParameters.ts, 18, 5))
89+
90+
const overloadA: { one: number } = b.overload('test');
91+
>overloadA : Symbol(overloadA, Decl(intersectionOfCallsWithSameParameters.ts, 30, 5))
92+
>one : Symbol(one, Decl(intersectionOfCallsWithSameParameters.ts, 30, 18))
93+
>b.overload : Symbol(Both.overload, Decl(intersectionOfCallsWithSameParameters.ts, 10, 32), Decl(intersectionOfCallsWithSameParameters.ts, 11, 42), Decl(intersectionOfCallsWithSameParameters.ts, 12, 42))
94+
>b : Symbol(b, Decl(intersectionOfCallsWithSameParameters.ts, 28, 5))
95+
>overload : Symbol(Both.overload, Decl(intersectionOfCallsWithSameParameters.ts, 10, 32), Decl(intersectionOfCallsWithSameParameters.ts, 11, 42), Decl(intersectionOfCallsWithSameParameters.ts, 12, 42))
96+
97+
const overloadB: { two: number } = b.overload(4);
98+
>overloadB : Symbol(overloadB, Decl(intersectionOfCallsWithSameParameters.ts, 31, 5))
99+
>two : Symbol(two, Decl(intersectionOfCallsWithSameParameters.ts, 31, 18))
100+
>b.overload : Symbol(Both.overload, Decl(intersectionOfCallsWithSameParameters.ts, 10, 32), Decl(intersectionOfCallsWithSameParameters.ts, 11, 42), Decl(intersectionOfCallsWithSameParameters.ts, 12, 42))
101+
>b : Symbol(b, Decl(intersectionOfCallsWithSameParameters.ts, 28, 5))
102+
>overload : Symbol(Both.overload, Decl(intersectionOfCallsWithSameParameters.ts, 10, 32), Decl(intersectionOfCallsWithSameParameters.ts, 11, 42), Decl(intersectionOfCallsWithSameParameters.ts, 12, 42))
103+
104+
const bAs: One & Two = b;
105+
>bAs : Symbol(bAs, Decl(intersectionOfCallsWithSameParameters.ts, 32, 5))
106+
>One : Symbol(One, Decl(intersectionOfCallsWithSameParameters.ts, 0, 0))
107+
>Two : Symbol(Two, Decl(intersectionOfCallsWithSameParameters.ts, 3, 1))
108+
>b : Symbol(b, Decl(intersectionOfCallsWithSameParameters.ts, 28, 5))
109+
110+
const asIntersect: { one: number, two: number } = bAs.intersect('test');
111+
>asIntersect : Symbol(asIntersect, Decl(intersectionOfCallsWithSameParameters.ts, 33, 5))
112+
>one : Symbol(one, Decl(intersectionOfCallsWithSameParameters.ts, 33, 20))
113+
>two : Symbol(two, Decl(intersectionOfCallsWithSameParameters.ts, 33, 33))
114+
>bAs.intersect : Symbol(intersect, Decl(intersectionOfCallsWithSameParameters.ts, 1, 42), Decl(intersectionOfCallsWithSameParameters.ts, 6, 42))
115+
>bAs : Symbol(bAs, Decl(intersectionOfCallsWithSameParameters.ts, 32, 5))
116+
>intersect : Symbol(intersect, Decl(intersectionOfCallsWithSameParameters.ts, 1, 42), Decl(intersectionOfCallsWithSameParameters.ts, 6, 42))
117+
118+
const asOverloadA: { one: number } = bAs.overload('test');
119+
>asOverloadA : Symbol(asOverloadA, Decl(intersectionOfCallsWithSameParameters.ts, 34, 5))
120+
>one : Symbol(one, Decl(intersectionOfCallsWithSameParameters.ts, 34, 20))
121+
>bAs.overload : Symbol(overload, Decl(intersectionOfCallsWithSameParameters.ts, 0, 15), Decl(intersectionOfCallsWithSameParameters.ts, 5, 15))
122+
>bAs : Symbol(bAs, Decl(intersectionOfCallsWithSameParameters.ts, 32, 5))
123+
>overload : Symbol(overload, Decl(intersectionOfCallsWithSameParameters.ts, 0, 15), Decl(intersectionOfCallsWithSameParameters.ts, 5, 15))
124+
125+
const asOverloadB: { two: number } = bAs.overload(4);
126+
>asOverloadB : Symbol(asOverloadB, Decl(intersectionOfCallsWithSameParameters.ts, 35, 5))
127+
>two : Symbol(two, Decl(intersectionOfCallsWithSameParameters.ts, 35, 20))
128+
>bAs.overload : Symbol(overload, Decl(intersectionOfCallsWithSameParameters.ts, 0, 15), Decl(intersectionOfCallsWithSameParameters.ts, 5, 15))
129+
>bAs : Symbol(bAs, Decl(intersectionOfCallsWithSameParameters.ts, 32, 5))
130+
>overload : Symbol(overload, Decl(intersectionOfCallsWithSameParameters.ts, 0, 15), Decl(intersectionOfCallsWithSameParameters.ts, 5, 15))
131+
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
=== tests/cases/compiler/intersectionOfCallsWithSameParameters.ts ===
2+
interface One {
3+
overload(id: string): { one: number };
4+
>overload : (id: string) => { one: number; }
5+
>id : string
6+
>one : number
7+
8+
intersect(id: string): { one: number };
9+
>intersect : (id: string) => { one: number; }
10+
>id : string
11+
>one : number
12+
}
13+
14+
interface Two {
15+
overload(id: number): { two: number };
16+
>overload : (id: number) => { two: number; }
17+
>id : number
18+
>two : number
19+
20+
intersect(id: string): { two: number };
21+
>intersect : (id: string) => { two: number; }
22+
>id : string
23+
>two : number
24+
}
25+
26+
class Both implements One, Two {
27+
>Both : Both
28+
29+
overload(id: number): { two: number };
30+
>overload : { (id: number): { two: number; }; (id: string): { one: number; }; }
31+
>id : number
32+
>two : number
33+
34+
overload(id: string): { one: number };
35+
>overload : { (id: number): { two: number; }; (id: string): { one: number; }; }
36+
>id : string
37+
>one : number
38+
39+
overload(id: string | number): { one: number, two: number } {
40+
>overload : { (id: number): { two: number; }; (id: string): { one: number; }; }
41+
>id : string | number
42+
>one : number
43+
>two : number
44+
45+
return {
46+
>{ one: 1, two: 2 } : { one: number; two: number; }
47+
48+
one: 1,
49+
>one : number
50+
>1 : 1
51+
52+
two: 2
53+
>two : number
54+
>2 : 2
55+
56+
};
57+
}
58+
59+
intersect(id: string): { one: number, two: number } {
60+
>intersect : (id: string) => { one: number; two: number; }
61+
>id : string
62+
>one : number
63+
>two : number
64+
65+
return {
66+
>{ one: 1, two: 2 } : { one: number; two: number; }
67+
68+
one: 1,
69+
>one : number
70+
>1 : 1
71+
72+
two: 2
73+
>two : number
74+
>2 : 2
75+
76+
};
77+
}
78+
}
79+
80+
const b = new Both();
81+
>b : Both
82+
>new Both() : Both
83+
>Both : typeof Both
84+
85+
const intersect: { one: number, two: number } = b.intersect('test');
86+
>intersect : { one: number; two: number; }
87+
>one : number
88+
>two : number
89+
>b.intersect('test') : { one: number; two: number; }
90+
>b.intersect : (id: string) => { one: number; two: number; }
91+
>b : Both
92+
>intersect : (id: string) => { one: number; two: number; }
93+
>'test' : "test"
94+
95+
const overloadA: { one: number } = b.overload('test');
96+
>overloadA : { one: number; }
97+
>one : number
98+
>b.overload('test') : { one: number; }
99+
>b.overload : { (id: number): { two: number; }; (id: string): { one: number; }; }
100+
>b : Both
101+
>overload : { (id: number): { two: number; }; (id: string): { one: number; }; }
102+
>'test' : "test"
103+
104+
const overloadB: { two: number } = b.overload(4);
105+
>overloadB : { two: number; }
106+
>two : number
107+
>b.overload(4) : { two: number; }
108+
>b.overload : { (id: number): { two: number; }; (id: string): { one: number; }; }
109+
>b : Both
110+
>overload : { (id: number): { two: number; }; (id: string): { one: number; }; }
111+
>4 : 4
112+
113+
const bAs: One & Two = b;
114+
>bAs : One & Two
115+
>b : Both
116+
117+
const asIntersect: { one: number, two: number } = bAs.intersect('test');
118+
>asIntersect : { one: number; two: number; }
119+
>one : number
120+
>two : number
121+
>bAs.intersect('test') : { one: number; } & { two: number; }
122+
>bAs.intersect : ((id: string) => { one: number; }) & ((id: string) => { two: number; })
123+
>bAs : One & Two
124+
>intersect : ((id: string) => { one: number; }) & ((id: string) => { two: number; })
125+
>'test' : "test"
126+
127+
const asOverloadA: { one: number } = bAs.overload('test');
128+
>asOverloadA : { one: number; }
129+
>one : number
130+
>bAs.overload('test') : { one: number; }
131+
>bAs.overload : ((id: string) => { one: number; }) & ((id: number) => { two: number; })
132+
>bAs : One & Two
133+
>overload : ((id: string) => { one: number; }) & ((id: number) => { two: number; })
134+
>'test' : "test"
135+
136+
const asOverloadB: { two: number } = bAs.overload(4);
137+
>asOverloadB : { two: number; }
138+
>two : number
139+
>bAs.overload(4) : { two: number; }
140+
>bAs.overload : ((id: string) => { one: number; }) & ((id: number) => { two: number; })
141+
>bAs : One & Two
142+
>overload : ((id: string) => { one: number; }) & ((id: number) => { two: number; })
143+
>4 : 4
144+

0 commit comments

Comments
 (0)