Skip to content

Commit 98bbb22

Browse files
committed
Add tests
1 parent aa0ea51 commit 98bbb22

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

tests/cases/conformance/types/intersection/intersectionReduction.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @strict
1+
// @strict: false
22

33
declare const sym1: unique symbol;
44
declare const sym2: unique symbol;
@@ -13,3 +13,46 @@ type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never
1313

1414
type T10 = string & ('a' | 'b'); // 'a' | 'b'
1515
type T11 = (string | number) & ('a' | 10); // 'a' | 10
16+
17+
type N1 = 'a' & 'b';
18+
type N2 = { a: string } & null;
19+
type N3 = { a: string } & undefined;
20+
type N4 = string & number;
21+
type N5 = number & object;
22+
type N6 = symbol & string;
23+
type N7 = void & string;
24+
25+
type X = { x: string };
26+
27+
type X1 = X | 'a' & 'b';
28+
type X2 = X | { a: string } & null;
29+
type X3 = X | { a: string } & undefined;
30+
type X4 = X | string & number;
31+
type X5 = X | number & object;
32+
type X6 = X | symbol & string;
33+
type X7 = X | void & string;
34+
35+
// Repro from #31663
36+
37+
const x1 = { a: 'foo', b: 42 };
38+
const x2 = { a: 'foo', b: true };
39+
40+
declare let k: 'a' | 'b';
41+
42+
x1[k] = 'bar' as any; // Error
43+
x2[k] = 'bar' as any; // Error
44+
45+
const enum Tag1 {}
46+
const enum Tag2 {}
47+
48+
declare let s1: string & Tag1;
49+
declare let s2: string & Tag2;
50+
51+
declare let t1: string & Tag1 | undefined;
52+
declare let t2: string & Tag2 | undefined;
53+
54+
s1 = s2;
55+
s2 = s1;
56+
57+
t1 = t2;
58+
t2 = t1;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// @strict: true
2+
3+
declare const sym1: unique symbol;
4+
declare const sym2: unique symbol;
5+
6+
type T1 = string & 'a'; // 'a'
7+
type T2 = 'a' & string & 'b'; // never
8+
type T3 = number & 10; // 10
9+
type T4 = 10 & number & 20; // never
10+
type T5 = symbol & typeof sym1; // typeof sym1
11+
type T6 = typeof sym1 & symbol & typeof sym2; // never
12+
type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never
13+
14+
type T10 = string & ('a' | 'b'); // 'a' | 'b'
15+
type T11 = (string | number) & ('a' | 10); // 'a' | 10
16+
17+
type N1 = 'a' & 'b';
18+
type N2 = { a: string } & null;
19+
type N3 = { a: string } & undefined;
20+
type N4 = string & number;
21+
type N5 = number & object;
22+
type N6 = symbol & string;
23+
type N7 = void & string;
24+
25+
type X = { x: string };
26+
27+
type X1 = X | 'a' & 'b';
28+
type X2 = X | { a: string } & null;
29+
type X3 = X | { a: string } & undefined;
30+
type X4 = X | string & number;
31+
type X5 = X | number & object;
32+
type X6 = X | symbol & string;
33+
type X7 = X | void & string;
34+
35+
// Repro from #31663
36+
37+
const x1 = { a: 'foo', b: 42 };
38+
const x2 = { a: 'foo', b: true };
39+
40+
declare let k: 'a' | 'b';
41+
42+
x1[k] = 'bar' as any; // Error
43+
x2[k] = 'bar' as any; // Error
44+
45+
const enum Tag1 {}
46+
const enum Tag2 {}
47+
48+
declare let s1: string & Tag1;
49+
declare let s2: string & Tag2;
50+
51+
declare let t1: string & Tag1 | undefined;
52+
declare let t2: string & Tag2 | undefined;
53+
54+
s1 = s2;
55+
s2 = s1;
56+
57+
t1 = t2;
58+
t2 = t1;

0 commit comments

Comments
 (0)