Skip to content

Commit 806ffbb

Browse files
committed
Add tests
1 parent f66a633 commit 806ffbb

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
relationComplexityError.ts(12,5): error TS2322: Type 'T1 & T2' is not assignable to type 'T1 | null'.
2+
relationComplexityError.ts(12,5): error TS2855: Excessive complexity comparing types 'T1 & T2' and 'T1 | null'.
3+
4+
5+
==== relationComplexityError.ts (2 errors) ====
6+
// Repro from #55630
7+
8+
type Digits = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
9+
type T1 = `${Digits}${Digits}${Digits}${Digits}` | undefined;
10+
type T2 = { a: string } | { b: number };
11+
12+
function f1(x: T1, y: T1 & T2) {
13+
x = y;
14+
}
15+
16+
function f2(x: T1 | null, y: T1 & T2) {
17+
x = y; // Complexity error
18+
~
19+
!!! error TS2322: Type 'T1 & T2' is not assignable to type 'T1 | null'.
20+
~~~~~
21+
!!! error TS2855: Excessive complexity comparing types 'T1 & T2' and 'T1 | null'.
22+
}
23+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//// [tests/cases/compiler/relationComplexityError.ts] ////
2+
3+
=== relationComplexityError.ts ===
4+
// Repro from #55630
5+
6+
type Digits = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
7+
>Digits : Symbol(Digits, Decl(relationComplexityError.ts, 0, 0))
8+
9+
type T1 = `${Digits}${Digits}${Digits}${Digits}` | undefined;
10+
>T1 : Symbol(T1, Decl(relationComplexityError.ts, 2, 72))
11+
>Digits : Symbol(Digits, Decl(relationComplexityError.ts, 0, 0))
12+
>Digits : Symbol(Digits, Decl(relationComplexityError.ts, 0, 0))
13+
>Digits : Symbol(Digits, Decl(relationComplexityError.ts, 0, 0))
14+
>Digits : Symbol(Digits, Decl(relationComplexityError.ts, 0, 0))
15+
16+
type T2 = { a: string } | { b: number };
17+
>T2 : Symbol(T2, Decl(relationComplexityError.ts, 3, 61))
18+
>a : Symbol(a, Decl(relationComplexityError.ts, 4, 11))
19+
>b : Symbol(b, Decl(relationComplexityError.ts, 4, 27))
20+
21+
function f1(x: T1, y: T1 & T2) {
22+
>f1 : Symbol(f1, Decl(relationComplexityError.ts, 4, 40))
23+
>x : Symbol(x, Decl(relationComplexityError.ts, 6, 12))
24+
>T1 : Symbol(T1, Decl(relationComplexityError.ts, 2, 72))
25+
>y : Symbol(y, Decl(relationComplexityError.ts, 6, 18))
26+
>T1 : Symbol(T1, Decl(relationComplexityError.ts, 2, 72))
27+
>T2 : Symbol(T2, Decl(relationComplexityError.ts, 3, 61))
28+
29+
x = y;
30+
>x : Symbol(x, Decl(relationComplexityError.ts, 6, 12))
31+
>y : Symbol(y, Decl(relationComplexityError.ts, 6, 18))
32+
}
33+
34+
function f2(x: T1 | null, y: T1 & T2) {
35+
>f2 : Symbol(f2, Decl(relationComplexityError.ts, 8, 1))
36+
>x : Symbol(x, Decl(relationComplexityError.ts, 10, 12))
37+
>T1 : Symbol(T1, Decl(relationComplexityError.ts, 2, 72))
38+
>y : Symbol(y, Decl(relationComplexityError.ts, 10, 25))
39+
>T1 : Symbol(T1, Decl(relationComplexityError.ts, 2, 72))
40+
>T2 : Symbol(T2, Decl(relationComplexityError.ts, 3, 61))
41+
42+
x = y; // Complexity error
43+
>x : Symbol(x, Decl(relationComplexityError.ts, 10, 12))
44+
>y : Symbol(y, Decl(relationComplexityError.ts, 10, 25))
45+
}
46+

tests/baselines/reference/relationComplexityError.types

Lines changed: 38 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// Repro from #55630
5+
6+
type Digits = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
7+
type T1 = `${Digits}${Digits}${Digits}${Digits}` | undefined;
8+
type T2 = { a: string } | { b: number };
9+
10+
function f1(x: T1, y: T1 & T2) {
11+
x = y;
12+
}
13+
14+
function f2(x: T1 | null, y: T1 & T2) {
15+
x = y; // Complexity error
16+
}

0 commit comments

Comments
 (0)