Flag mapped types with circular property types and do not attempt to print them structurally (#39552)

This commit is contained in:
Wesley Wigham 2020-07-15 11:19:43 -07:00 committed by GitHub
parent fcd4fcb3d7
commit f2c5643056
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 49 additions and 2 deletions

View file

@ -4577,8 +4577,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);
@ -10316,6 +10316,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);

View file

@ -5177,6 +5177,7 @@ namespace ts {
templateType?: Type;
modifiersType?: Type;
resolvedApparentType?: Type;
containsError?: boolean;
}
export interface EvolvingArrayType extends ObjectType {

View file

@ -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; }'.

View file

@ -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]

View file

@ -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))

View file

@ -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

View file

@ -0,0 +1,3 @@
type N<T, K extends string> = T | { [P in K]: N<T, K> }[K];
type M = N<number, "M">;