Skip to content

Commit 5dfda97

Browse files
author
hamza
committed
Fix stack overflow in error generation for recursive mapped types
Fixes #63090
1 parent c9e7428 commit 5dfda97

File tree

6 files changed

+482
-428
lines changed

6 files changed

+482
-428
lines changed

src/compiler/checker.ts

Lines changed: 429 additions & 428 deletions
Large diffs are not rendered by default.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
issue63090.ts(2,10): error TS2615: Type of property 'M' circularly references itself in mapped type '{ M: any; }'.
2+
issue63090.ts(2,10): error TS2615: Type of property 'M' circularly references itself in mapped type '{ [P in "M"]: any; }'.
3+
4+
5+
==== issue63090.ts (2 errors) ====
6+
type N<T, K extends string> = T | { [P in K]: N<keyof T, K> }[K];
7+
type M = N<number, "M">;
8+
~~~~~~~~~~~~~~
9+
!!! error TS2615: Type of property 'M' circularly references itself in mapped type '{ M: any; }'.
10+
~~~~~~~~~~~~~~
11+
!!! error TS2615: Type of property 'M' circularly references itself in mapped type '{ [P in "M"]: any; }'.
12+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [tests/cases/compiler/issue63090.ts] ////
2+
3+
//// [issue63090.ts]
4+
type N<T, K extends string> = T | { [P in K]: N<keyof T, K> }[K];
5+
type M = N<number, "M">;
6+
7+
8+
//// [issue63090.js]
9+
"use strict";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [tests/cases/compiler/issue63090.ts] ////
2+
3+
=== issue63090.ts ===
4+
type N<T, K extends string> = T | { [P in K]: N<keyof T, K> }[K];
5+
>N : Symbol(N, Decl(issue63090.ts, 0, 0))
6+
>T : Symbol(T, Decl(issue63090.ts, 0, 7))
7+
>K : Symbol(K, Decl(issue63090.ts, 0, 9))
8+
>T : Symbol(T, Decl(issue63090.ts, 0, 7))
9+
>P : Symbol(P, Decl(issue63090.ts, 0, 37))
10+
>K : Symbol(K, Decl(issue63090.ts, 0, 9))
11+
>N : Symbol(N, Decl(issue63090.ts, 0, 0))
12+
>T : Symbol(T, Decl(issue63090.ts, 0, 7))
13+
>K : Symbol(K, Decl(issue63090.ts, 0, 9))
14+
>K : Symbol(K, Decl(issue63090.ts, 0, 9))
15+
16+
type M = N<number, "M">;
17+
>M : Symbol(M, Decl(issue63090.ts, 0, 65))
18+
>N : Symbol(N, Decl(issue63090.ts, 0, 0))
19+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [tests/cases/compiler/issue63090.ts] ////
2+
3+
=== issue63090.ts ===
4+
type N<T, K extends string> = T | { [P in K]: N<keyof T, K> }[K];
5+
>N : N<T, K>
6+
> : ^^^^^^^
7+
8+
type M = N<number, "M">;
9+
>M : any
10+
> : ^^^
11+

tests/cases/compiler/issue63090.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type N<T, K extends string> = T | { [P in K]: N<keyof T, K> }[K];
2+
type M = N<number, "M">;

0 commit comments

Comments
 (0)