Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions 5 src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4572,8 +4572,8 @@ namespace ts {
}

function createTypeNodeFromObjectType(type: ObjectType): TypeNode {
if (isGenericMappedType(type)) {
return createMappedTypeNodeFromType(type);
if (isGenericMappedType(type) || (type as MappedType).containsError) {
return createMappedTypeNodeFromType(type as MappedType);
}

const resolved = resolveStructuredTypeMembers(type);
Expand Down Expand Up @@ -10309,6 +10309,7 @@ namespace ts {
function getTypeOfMappedSymbol(symbol: MappedSymbol) {
if (!symbol.type) {
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
symbol.mappedType.containsError = true;
return errorType;
}
const templateType = getTemplateTypeFromMappedType(<MappedType>symbol.mappedType.target || symbol.mappedType);
Expand Down
1 change: 1 addition & 0 deletions 1 src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5168,6 +5168,7 @@ namespace ts {
templateType?: Type;
modifiersType?: Type;
resolvedApparentType?: Type;
containsError?: boolean;
}

export interface EvolvingArrayType extends ObjectType {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tests/cases/compiler/recursivelyExpandingUnionNoStackoverflow.ts(3,10): error TS2589: Type instantiation is excessively deep and possibly infinite.
tests/cases/compiler/recursivelyExpandingUnionNoStackoverflow.ts(3,10): error TS2615: Type of property 'M' circularly references itself in mapped type '{ [P in "M"]: any; }'.


==== tests/cases/compiler/recursivelyExpandingUnionNoStackoverflow.ts (2 errors) ====
type N<T, K extends string> = T | { [P in K]: N<T, K> }[K];

type M = N<number, "M">;
~~~~~~~~~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
~~~~~~~~~~~~~~
!!! error TS2615: Type of property 'M' circularly references itself in mapped type '{ [P in "M"]: any; }'.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [recursivelyExpandingUnionNoStackoverflow.ts]
type N<T, K extends string> = T | { [P in K]: N<T, K> }[K];

type M = N<number, "M">;

//// [recursivelyExpandingUnionNoStackoverflow.js]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== tests/cases/compiler/recursivelyExpandingUnionNoStackoverflow.ts ===
type N<T, K extends string> = T | { [P in K]: N<T, K> }[K];
>N : Symbol(N, Decl(recursivelyExpandingUnionNoStackoverflow.ts, 0, 0))
>T : Symbol(T, Decl(recursivelyExpandingUnionNoStackoverflow.ts, 0, 7))
>K : Symbol(K, Decl(recursivelyExpandingUnionNoStackoverflow.ts, 0, 9))
>T : Symbol(T, Decl(recursivelyExpandingUnionNoStackoverflow.ts, 0, 7))
>P : Symbol(P, Decl(recursivelyExpandingUnionNoStackoverflow.ts, 0, 37))
>K : Symbol(K, Decl(recursivelyExpandingUnionNoStackoverflow.ts, 0, 9))
>N : Symbol(N, Decl(recursivelyExpandingUnionNoStackoverflow.ts, 0, 0))
>T : Symbol(T, Decl(recursivelyExpandingUnionNoStackoverflow.ts, 0, 7))
>K : Symbol(K, Decl(recursivelyExpandingUnionNoStackoverflow.ts, 0, 9))
>K : Symbol(K, Decl(recursivelyExpandingUnionNoStackoverflow.ts, 0, 9))

type M = N<number, "M">;
>M : Symbol(M, Decl(recursivelyExpandingUnionNoStackoverflow.ts, 0, 59))
>N : Symbol(N, Decl(recursivelyExpandingUnionNoStackoverflow.ts, 0, 0))

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/compiler/recursivelyExpandingUnionNoStackoverflow.ts ===
type N<T, K extends string> = T | { [P in K]: N<T, K> }[K];
>N : N<T, K>

type M = N<number, "M">;
>M : any

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type N<T, K extends string> = T | { [P in K]: N<T, K> }[K];

type M = N<number, "M">;
Morty Proxy This is a proxified and sanitized view of the page, visit original site.