Skip to content

Commit d571034

Browse files
committed
Adding tests
1 parent d2955e8 commit d571034

17 files changed

+882
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(19,1): error TS2322: Type 'A' is not assignable to type 'A & B'.
2+
Type 'A' is not assignable to type 'B'.
3+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(20,1): error TS2322: Type 'B' is not assignable to type 'A & B'.
4+
Type 'B' is not assignable to type 'A'.
5+
Property 'a' is missing in type 'B'.
6+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(23,1): error TS2322: Type 'A | B' is not assignable to type '(A & B) | (C & D)'.
7+
Type 'A' is not assignable to type '(A & B) | (C & D)'.
8+
Type 'A' is not assignable to type 'C & D'.
9+
Type 'A' is not assignable to type 'C'.
10+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(25,1): error TS2322: Type 'C | D' is not assignable to type '(A & B) | (C & D)'.
11+
Type 'C' is not assignable to type '(A & B) | (C & D)'.
12+
Type 'C' is not assignable to type 'C & D'.
13+
Type 'C' is not assignable to type 'D'.
14+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(26,1): error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'A & B'.
15+
Type 'C & D' is not assignable to type 'A & B'.
16+
Type 'C & D' is not assignable to type 'A'.
17+
Type 'D' is not assignable to type 'A'.
18+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(27,1): error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'A | B'.
19+
Type 'C & D' is not assignable to type 'A | B'.
20+
Type 'C & D' is not assignable to type 'B'.
21+
Type 'D' is not assignable to type 'B'.
22+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(28,1): error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'C & D'.
23+
Type 'A & B' is not assignable to type 'C & D'.
24+
Type 'A & B' is not assignable to type 'C'.
25+
Type 'B' is not assignable to type 'C'.
26+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(29,1): error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'C | D'.
27+
Type 'A & B' is not assignable to type 'C | D'.
28+
Type 'A & B' is not assignable to type 'D'.
29+
Type 'B' is not assignable to type 'D'.
30+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(31,1): error TS2322: Type 'A & B' is not assignable to type '(A | B) & (C | D)'.
31+
Type 'A & B' is not assignable to type 'C | D'.
32+
Type 'A & B' is not assignable to type 'D'.
33+
Type 'B' is not assignable to type 'D'.
34+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(32,1): error TS2322: Type 'A | B' is not assignable to type '(A | B) & (C | D)'.
35+
Type 'A' is not assignable to type '(A | B) & (C | D)'.
36+
Type 'A' is not assignable to type 'C | D'.
37+
Type 'A' is not assignable to type 'D'.
38+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(33,1): error TS2322: Type 'C & D' is not assignable to type '(A | B) & (C | D)'.
39+
Type 'C & D' is not assignable to type 'A | B'.
40+
Type 'C & D' is not assignable to type 'B'.
41+
Type 'D' is not assignable to type 'B'.
42+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(34,1): error TS2322: Type 'C | D' is not assignable to type '(A | B) & (C | D)'.
43+
Type 'C' is not assignable to type '(A | B) & (C | D)'.
44+
Type 'C' is not assignable to type 'A | B'.
45+
Type 'C' is not assignable to type 'B'.
46+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(35,1): error TS2322: Type '(A | B) & (C | D)' is not assignable to type 'A & B'.
47+
Type '(A | B) & (C | D)' is not assignable to type 'A'.
48+
Type 'C | D' is not assignable to type 'A'.
49+
Type 'C' is not assignable to type 'A'.
50+
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(37,1): error TS2322: Type '(A | B) & (C | D)' is not assignable to type 'C & D'.
51+
Type '(A | B) & (C | D)' is not assignable to type 'C'.
52+
Type 'C | D' is not assignable to type 'C'.
53+
Type 'D' is not assignable to type 'C'.
54+
55+
56+
==== tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts (14 errors) ====
57+
interface A { a: string }
58+
interface B { b: string }
59+
interface C { c: string }
60+
interface D { d: string }
61+
62+
var a: A;
63+
var b: B;
64+
var c: C;
65+
var d: D;
66+
var anb: A & B;
67+
var aob: A | B;
68+
var cnd: C & D;
69+
var cod: C | D;
70+
var x: A & B | C & D;
71+
var y: (A | B) & (C | D);
72+
73+
a = anb; // Ok
74+
b = anb; // Ok
75+
anb = a;
76+
~~~
77+
!!! error TS2322: Type 'A' is not assignable to type 'A & B'.
78+
!!! error TS2322: Type 'A' is not assignable to type 'B'.
79+
anb = b;
80+
~~~
81+
!!! error TS2322: Type 'B' is not assignable to type 'A & B'.
82+
!!! error TS2322: Type 'B' is not assignable to type 'A'.
83+
!!! error TS2322: Property 'a' is missing in type 'B'.
84+
85+
x = anb; // Ok
86+
x = aob;
87+
~
88+
!!! error TS2322: Type 'A | B' is not assignable to type '(A & B) | (C & D)'.
89+
!!! error TS2322: Type 'A' is not assignable to type '(A & B) | (C & D)'.
90+
!!! error TS2322: Type 'A' is not assignable to type 'C & D'.
91+
!!! error TS2322: Type 'A' is not assignable to type 'C'.
92+
x = cnd; // Ok
93+
x = cod;
94+
~
95+
!!! error TS2322: Type 'C | D' is not assignable to type '(A & B) | (C & D)'.
96+
!!! error TS2322: Type 'C' is not assignable to type '(A & B) | (C & D)'.
97+
!!! error TS2322: Type 'C' is not assignable to type 'C & D'.
98+
!!! error TS2322: Type 'C' is not assignable to type 'D'.
99+
anb = x;
100+
~~~
101+
!!! error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'A & B'.
102+
!!! error TS2322: Type 'C & D' is not assignable to type 'A & B'.
103+
!!! error TS2322: Type 'C & D' is not assignable to type 'A'.
104+
!!! error TS2322: Type 'D' is not assignable to type 'A'.
105+
aob = x;
106+
~~~
107+
!!! error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'A | B'.
108+
!!! error TS2322: Type 'C & D' is not assignable to type 'A | B'.
109+
!!! error TS2322: Type 'C & D' is not assignable to type 'B'.
110+
!!! error TS2322: Type 'D' is not assignable to type 'B'.
111+
cnd = x;
112+
~~~
113+
!!! error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'C & D'.
114+
!!! error TS2322: Type 'A & B' is not assignable to type 'C & D'.
115+
!!! error TS2322: Type 'A & B' is not assignable to type 'C'.
116+
!!! error TS2322: Type 'B' is not assignable to type 'C'.
117+
cod = x;
118+
~~~
119+
!!! error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'C | D'.
120+
!!! error TS2322: Type 'A & B' is not assignable to type 'C | D'.
121+
!!! error TS2322: Type 'A & B' is not assignable to type 'D'.
122+
!!! error TS2322: Type 'B' is not assignable to type 'D'.
123+
124+
y = anb;
125+
~
126+
!!! error TS2322: Type 'A & B' is not assignable to type '(A | B) & (C | D)'.
127+
!!! error TS2322: Type 'A & B' is not assignable to type 'C | D'.
128+
!!! error TS2322: Type 'A & B' is not assignable to type 'D'.
129+
!!! error TS2322: Type 'B' is not assignable to type 'D'.
130+
y = aob;
131+
~
132+
!!! error TS2322: Type 'A | B' is not assignable to type '(A | B) & (C | D)'.
133+
!!! error TS2322: Type 'A' is not assignable to type '(A | B) & (C | D)'.
134+
!!! error TS2322: Type 'A' is not assignable to type 'C | D'.
135+
!!! error TS2322: Type 'A' is not assignable to type 'D'.
136+
y = cnd;
137+
~
138+
!!! error TS2322: Type 'C & D' is not assignable to type '(A | B) & (C | D)'.
139+
!!! error TS2322: Type 'C & D' is not assignable to type 'A | B'.
140+
!!! error TS2322: Type 'C & D' is not assignable to type 'B'.
141+
!!! error TS2322: Type 'D' is not assignable to type 'B'.
142+
y = cod;
143+
~
144+
!!! error TS2322: Type 'C | D' is not assignable to type '(A | B) & (C | D)'.
145+
!!! error TS2322: Type 'C' is not assignable to type '(A | B) & (C | D)'.
146+
!!! error TS2322: Type 'C' is not assignable to type 'A | B'.
147+
!!! error TS2322: Type 'C' is not assignable to type 'B'.
148+
anb = y;
149+
~~~
150+
!!! error TS2322: Type '(A | B) & (C | D)' is not assignable to type 'A & B'.
151+
!!! error TS2322: Type '(A | B) & (C | D)' is not assignable to type 'A'.
152+
!!! error TS2322: Type 'C | D' is not assignable to type 'A'.
153+
!!! error TS2322: Type 'C' is not assignable to type 'A'.
154+
aob = y; // Ok
155+
cnd = y;
156+
~~~
157+
!!! error TS2322: Type '(A | B) & (C | D)' is not assignable to type 'C & D'.
158+
!!! error TS2322: Type '(A | B) & (C | D)' is not assignable to type 'C'.
159+
!!! error TS2322: Type 'C | D' is not assignable to type 'C'.
160+
!!! error TS2322: Type 'D' is not assignable to type 'C'.
161+
cod = y; // Ok
162+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//// [intersectionAndUnionTypes.ts]
2+
interface A { a: string }
3+
interface B { b: string }
4+
interface C { c: string }
5+
interface D { d: string }
6+
7+
var a: A;
8+
var b: B;
9+
var c: C;
10+
var d: D;
11+
var anb: A & B;
12+
var aob: A | B;
13+
var cnd: C & D;
14+
var cod: C | D;
15+
var x: A & B | C & D;
16+
var y: (A | B) & (C | D);
17+
18+
a = anb; // Ok
19+
b = anb; // Ok
20+
anb = a;
21+
anb = b;
22+
23+
x = anb; // Ok
24+
x = aob;
25+
x = cnd; // Ok
26+
x = cod;
27+
anb = x;
28+
aob = x;
29+
cnd = x;
30+
cod = x;
31+
32+
y = anb;
33+
y = aob;
34+
y = cnd;
35+
y = cod;
36+
anb = y;
37+
aob = y; // Ok
38+
cnd = y;
39+
cod = y; // Ok
40+
41+
42+
//// [intersectionAndUnionTypes.js]
43+
var a;
44+
var b;
45+
var c;
46+
var d;
47+
var anb;
48+
var aob;
49+
var cnd;
50+
var cod;
51+
var x;
52+
var y;
53+
a = anb; // Ok
54+
b = anb; // Ok
55+
anb = a;
56+
anb = b;
57+
x = anb; // Ok
58+
x = aob;
59+
x = cnd; // Ok
60+
x = cod;
61+
anb = x;
62+
aob = x;
63+
cnd = x;
64+
cod = x;
65+
y = anb;
66+
y = aob;
67+
y = cnd;
68+
y = cod;
69+
anb = y;
70+
aob = y; // Ok
71+
cnd = y;
72+
cod = y; // Ok
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [intersectionTypeEquivalence.ts]
2+
interface A { a: string }
3+
interface B { b: string }
4+
interface C { c: string }
5+
6+
// A & B is equivalent to B & A.
7+
var y: A & B;
8+
var y : B & A;
9+
10+
// AB & C is equivalent to A & BC, where AB is A & B and BC is B & C.
11+
var z : A & B & C;
12+
var z : (A & B) & C;
13+
var z : A & (B & C);
14+
var ab : A & B;
15+
var bc : B & C;
16+
var z1: typeof ab & C;
17+
var z1: A & typeof bc;
18+
19+
20+
//// [intersectionTypeEquivalence.js]
21+
// A & B is equivalent to B & A.
22+
var y;
23+
var y;
24+
// AB & C is equivalent to A & BC, where AB is A & B and BC is B & C.
25+
var z;
26+
var z;
27+
var z;
28+
var ab;
29+
var bc;
30+
var z1;
31+
var z1;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
=== tests/cases/conformance/types/intersection/intersectionTypeEquivalence.ts ===
2+
interface A { a: string }
3+
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
4+
>a : Symbol(a, Decl(intersectionTypeEquivalence.ts, 0, 13))
5+
6+
interface B { b: string }
7+
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
8+
>b : Symbol(b, Decl(intersectionTypeEquivalence.ts, 1, 13))
9+
10+
interface C { c: string }
11+
>C : Symbol(C, Decl(intersectionTypeEquivalence.ts, 1, 25))
12+
>c : Symbol(c, Decl(intersectionTypeEquivalence.ts, 2, 13))
13+
14+
// A & B is equivalent to B & A.
15+
var y: A & B;
16+
>y : Symbol(y, Decl(intersectionTypeEquivalence.ts, 5, 3), Decl(intersectionTypeEquivalence.ts, 6, 3))
17+
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
18+
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
19+
20+
var y : B & A;
21+
>y : Symbol(y, Decl(intersectionTypeEquivalence.ts, 5, 3), Decl(intersectionTypeEquivalence.ts, 6, 3))
22+
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
23+
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
24+
25+
// AB & C is equivalent to A & BC, where AB is A & B and BC is B & C.
26+
var z : A & B & C;
27+
>z : Symbol(z, Decl(intersectionTypeEquivalence.ts, 9, 3), Decl(intersectionTypeEquivalence.ts, 10, 3), Decl(intersectionTypeEquivalence.ts, 11, 3))
28+
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
29+
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
30+
>C : Symbol(C, Decl(intersectionTypeEquivalence.ts, 1, 25))
31+
32+
var z : (A & B) & C;
33+
>z : Symbol(z, Decl(intersectionTypeEquivalence.ts, 9, 3), Decl(intersectionTypeEquivalence.ts, 10, 3), Decl(intersectionTypeEquivalence.ts, 11, 3))
34+
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
35+
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
36+
>C : Symbol(C, Decl(intersectionTypeEquivalence.ts, 1, 25))
37+
38+
var z : A & (B & C);
39+
>z : Symbol(z, Decl(intersectionTypeEquivalence.ts, 9, 3), Decl(intersectionTypeEquivalence.ts, 10, 3), Decl(intersectionTypeEquivalence.ts, 11, 3))
40+
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
41+
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
42+
>C : Symbol(C, Decl(intersectionTypeEquivalence.ts, 1, 25))
43+
44+
var ab : A & B;
45+
>ab : Symbol(ab, Decl(intersectionTypeEquivalence.ts, 12, 3))
46+
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
47+
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
48+
49+
var bc : B & C;
50+
>bc : Symbol(bc, Decl(intersectionTypeEquivalence.ts, 13, 3))
51+
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
52+
>C : Symbol(C, Decl(intersectionTypeEquivalence.ts, 1, 25))
53+
54+
var z1: typeof ab & C;
55+
>z1 : Symbol(z1, Decl(intersectionTypeEquivalence.ts, 14, 3), Decl(intersectionTypeEquivalence.ts, 15, 3))
56+
>ab : Symbol(ab, Decl(intersectionTypeEquivalence.ts, 12, 3))
57+
>C : Symbol(C, Decl(intersectionTypeEquivalence.ts, 1, 25))
58+
59+
var z1: A & typeof bc;
60+
>z1 : Symbol(z1, Decl(intersectionTypeEquivalence.ts, 14, 3), Decl(intersectionTypeEquivalence.ts, 15, 3))
61+
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
62+
>bc : Symbol(bc, Decl(intersectionTypeEquivalence.ts, 13, 3))
63+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
=== tests/cases/conformance/types/intersection/intersectionTypeEquivalence.ts ===
2+
interface A { a: string }
3+
>A : A
4+
>a : string
5+
6+
interface B { b: string }
7+
>B : B
8+
>b : string
9+
10+
interface C { c: string }
11+
>C : C
12+
>c : string
13+
14+
// A & B is equivalent to B & A.
15+
var y: A & B;
16+
>y : A & B
17+
>A : A
18+
>B : B
19+
20+
var y : B & A;
21+
>y : A & B
22+
>B : B
23+
>A : A
24+
25+
// AB & C is equivalent to A & BC, where AB is A & B and BC is B & C.
26+
var z : A & B & C;
27+
>z : A & B & C
28+
>A : A
29+
>B : B
30+
>C : C
31+
32+
var z : (A & B) & C;
33+
>z : A & B & C
34+
>A : A
35+
>B : B
36+
>C : C
37+
38+
var z : A & (B & C);
39+
>z : A & B & C
40+
>A : A
41+
>B : B
42+
>C : C
43+
44+
var ab : A & B;
45+
>ab : A & B
46+
>A : A
47+
>B : B
48+
49+
var bc : B & C;
50+
>bc : B & C
51+
>B : B
52+
>C : C
53+
54+
var z1: typeof ab & C;
55+
>z1 : A & B & C
56+
>ab : A & B
57+
>C : C
58+
59+
var z1: A & typeof bc;
60+
>z1 : A & B & C
61+
>A : A
62+
>bc : B & C
63+

0 commit comments

Comments
 (0)