diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 41580a1ef7..ee12266c9e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16346,7 +16346,7 @@ namespace ts { // for finite but deeply expanding indexed accesses (eg, for `Q[P1][P2][P3][P4][P5]`). function isDeeplyNestedType(type: Type, stack: Type[], depth: number): boolean { // We track all object types that have an associated symbol (representing the origin of the type) - if (depth >= 5 && type.flags & TypeFlags.Object) { + if (depth >= 5 && type.flags & TypeFlags.Object && !isObjectOrArrayLiteralType(type)) { const symbol = type.symbol; if (symbol) { let count = 0; diff --git a/tests/baselines/reference/deeplyNestedCheck.errors.txt b/tests/baselines/reference/deeplyNestedCheck.errors.txt new file mode 100644 index 0000000000..d76c8c3386 --- /dev/null +++ b/tests/baselines/reference/deeplyNestedCheck.errors.txt @@ -0,0 +1,69 @@ +tests/cases/compiler/deeplyNestedCheck.ts(34,25): error TS2741: Property 'i' is missing in type '{}' but required in type 'H'. +tests/cases/compiler/deeplyNestedCheck.ts(52,35): error TS2322: Type 'number' is not assignable to type 'string'. +tests/cases/compiler/deeplyNestedCheck.ts(53,50): error TS2322: Type 'number' is not assignable to type 'string'. + + +==== tests/cases/compiler/deeplyNestedCheck.ts (3 errors) ==== + // Repro from #14794 + + interface DataSnapshot { + child(path: string): DataSnapshot; + } + + interface Snapshot extends DataSnapshot { + child>(path: U): Snapshot; + } + + // Repro from 34619 + + interface A { b: B[] } + interface B { c: C } + interface C { d: D[] } + interface D { e: E[] } + interface E { f: F[] } + interface F { g: G } + interface G { h: H[] } + interface H { i: string } + + const x: A = { + b: [ + { + c: { + d: [ + { + e: [ + { + f: [ + { + g: { + h: [ + { + ~ + // i: '', + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + }, + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2741: Property 'i' is missing in type '{}' but required in type 'H'. +!!! related TS2728 tests/cases/compiler/deeplyNestedCheck.ts:20:15: 'i' is declared here. + ], + }, + }, + ], + }, + ], + }, + ], + }, + }, + ], + }; + + // Repro from 34619 + + const a1: string[][][][][] = [[[[[42]]]]]; + ~~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. + const a2: string[][][][][][][][][][] = [[[[[[[[[[42]]]]]]]]]]; + ~~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. + \ No newline at end of file diff --git a/tests/baselines/reference/deeplyNestedCheck.js b/tests/baselines/reference/deeplyNestedCheck.js index ccd234e258..1dd6b44212 100644 --- a/tests/baselines/reference/deeplyNestedCheck.js +++ b/tests/baselines/reference/deeplyNestedCheck.js @@ -8,7 +8,81 @@ interface DataSnapshot { interface Snapshot extends DataSnapshot { child>(path: U): Snapshot; } + +// Repro from 34619 + +interface A { b: B[] } +interface B { c: C } +interface C { d: D[] } +interface D { e: E[] } +interface E { f: F[] } +interface F { g: G } +interface G { h: H[] } +interface H { i: string } + +const x: A = { + b: [ + { + c: { + d: [ + { + e: [ + { + f: [ + { + g: { + h: [ + { + // i: '', + }, + ], + }, + }, + ], + }, + ], + }, + ], + }, + }, + ], +}; + +// Repro from 34619 + +const a1: string[][][][][] = [[[[[42]]]]]; +const a2: string[][][][][][][][][][] = [[[[[[[[[[42]]]]]]]]]]; //// [deeplyNestedCheck.js] // Repro from #14794 +var x = { + b: [ + { + c: { + d: [ + { + e: [ + { + f: [ + { + g: { + h: [ + { + // i: '', + }, + ] + } + }, + ] + }, + ] + }, + ] + } + }, + ] +}; +// Repro from 34619 +var a1 = [[[[[42]]]]]; +var a2 = [[[[[[[[[[42]]]]]]]]]]; diff --git a/tests/baselines/reference/deeplyNestedCheck.symbols b/tests/baselines/reference/deeplyNestedCheck.symbols index 8da69e1254..4e0b16a2ad 100644 --- a/tests/baselines/reference/deeplyNestedCheck.symbols +++ b/tests/baselines/reference/deeplyNestedCheck.symbols @@ -28,3 +28,92 @@ interface Snapshot extends DataSnapshot { >U : Symbol(U, Decl(deeplyNestedCheck.ts, 7, 8)) } +// Repro from 34619 + +interface A { b: B[] } +>A : Symbol(A, Decl(deeplyNestedCheck.ts, 8, 1)) +>b : Symbol(A.b, Decl(deeplyNestedCheck.ts, 12, 13)) +>B : Symbol(B, Decl(deeplyNestedCheck.ts, 12, 22)) + +interface B { c: C } +>B : Symbol(B, Decl(deeplyNestedCheck.ts, 12, 22)) +>c : Symbol(B.c, Decl(deeplyNestedCheck.ts, 13, 13)) +>C : Symbol(C, Decl(deeplyNestedCheck.ts, 13, 20)) + +interface C { d: D[] } +>C : Symbol(C, Decl(deeplyNestedCheck.ts, 13, 20)) +>d : Symbol(C.d, Decl(deeplyNestedCheck.ts, 14, 13)) +>D : Symbol(D, Decl(deeplyNestedCheck.ts, 14, 22)) + +interface D { e: E[] } +>D : Symbol(D, Decl(deeplyNestedCheck.ts, 14, 22)) +>e : Symbol(D.e, Decl(deeplyNestedCheck.ts, 15, 13)) +>E : Symbol(E, Decl(deeplyNestedCheck.ts, 15, 22)) + +interface E { f: F[] } +>E : Symbol(E, Decl(deeplyNestedCheck.ts, 15, 22)) +>f : Symbol(E.f, Decl(deeplyNestedCheck.ts, 16, 13)) +>F : Symbol(F, Decl(deeplyNestedCheck.ts, 16, 22)) + +interface F { g: G } +>F : Symbol(F, Decl(deeplyNestedCheck.ts, 16, 22)) +>g : Symbol(F.g, Decl(deeplyNestedCheck.ts, 17, 13)) +>G : Symbol(G, Decl(deeplyNestedCheck.ts, 17, 20)) + +interface G { h: H[] } +>G : Symbol(G, Decl(deeplyNestedCheck.ts, 17, 20)) +>h : Symbol(G.h, Decl(deeplyNestedCheck.ts, 18, 13)) +>H : Symbol(H, Decl(deeplyNestedCheck.ts, 18, 22)) + +interface H { i: string } +>H : Symbol(H, Decl(deeplyNestedCheck.ts, 18, 22)) +>i : Symbol(H.i, Decl(deeplyNestedCheck.ts, 19, 13)) + +const x: A = { +>x : Symbol(x, Decl(deeplyNestedCheck.ts, 21, 5)) +>A : Symbol(A, Decl(deeplyNestedCheck.ts, 8, 1)) + + b: [ +>b : Symbol(b, Decl(deeplyNestedCheck.ts, 21, 14)) + { + c: { +>c : Symbol(c, Decl(deeplyNestedCheck.ts, 23, 5)) + + d: [ +>d : Symbol(d, Decl(deeplyNestedCheck.ts, 24, 10)) + { + e: [ +>e : Symbol(e, Decl(deeplyNestedCheck.ts, 26, 11)) + { + f: [ +>f : Symbol(f, Decl(deeplyNestedCheck.ts, 28, 15)) + { + g: { +>g : Symbol(g, Decl(deeplyNestedCheck.ts, 30, 19)) + + h: [ +>h : Symbol(h, Decl(deeplyNestedCheck.ts, 31, 24)) + { + // i: '', + }, + ], + }, + }, + ], + }, + ], + }, + ], + }, + }, + ], +}; + +// Repro from 34619 + +const a1: string[][][][][] = [[[[[42]]]]]; +>a1 : Symbol(a1, Decl(deeplyNestedCheck.ts, 51, 5)) + +const a2: string[][][][][][][][][][] = [[[[[[[[[[42]]]]]]]]]]; +>a2 : Symbol(a2, Decl(deeplyNestedCheck.ts, 52, 5)) + diff --git a/tests/baselines/reference/deeplyNestedCheck.types b/tests/baselines/reference/deeplyNestedCheck.types index a84982c029..9a13ccfc92 100644 --- a/tests/baselines/reference/deeplyNestedCheck.types +++ b/tests/baselines/reference/deeplyNestedCheck.types @@ -13,3 +13,111 @@ interface Snapshot extends DataSnapshot { >path : U } +// Repro from 34619 + +interface A { b: B[] } +>b : B[] + +interface B { c: C } +>c : C + +interface C { d: D[] } +>d : D[] + +interface D { e: E[] } +>e : E[] + +interface E { f: F[] } +>f : F[] + +interface F { g: G } +>g : G + +interface G { h: H[] } +>h : H[] + +interface H { i: string } +>i : string + +const x: A = { +>x : A +>{ b: [ { c: { d: [ { e: [ { f: [ { g: { h: [ { // i: '', }, ], }, }, ], }, ], }, ], }, }, ],} : { b: { c: { d: { e: { f: { g: { h: {}[]; }; }[]; }[]; }[]; }; }[]; } + + b: [ +>b : { c: { d: { e: { f: { g: { h: {}[]; }; }[]; }[]; }[]; }; }[] +>[ { c: { d: [ { e: [ { f: [ { g: { h: [ { // i: '', }, ], }, }, ], }, ], }, ], }, }, ] : { c: { d: { e: { f: { g: { h: {}[]; }; }[]; }[]; }[]; }; }[] + { +>{ c: { d: [ { e: [ { f: [ { g: { h: [ { // i: '', }, ], }, }, ], }, ], }, ], }, } : { c: { d: { e: { f: { g: { h: {}[]; }; }[]; }[]; }[]; }; } + + c: { +>c : { d: { e: { f: { g: { h: {}[]; }; }[]; }[]; }[]; } +>{ d: [ { e: [ { f: [ { g: { h: [ { // i: '', }, ], }, }, ], }, ], }, ], } : { d: { e: { f: { g: { h: {}[]; }; }[]; }[]; }[]; } + + d: [ +>d : { e: { f: { g: { h: {}[]; }; }[]; }[]; }[] +>[ { e: [ { f: [ { g: { h: [ { // i: '', }, ], }, }, ], }, ], }, ] : { e: { f: { g: { h: {}[]; }; }[]; }[]; }[] + { +>{ e: [ { f: [ { g: { h: [ { // i: '', }, ], }, }, ], }, ], } : { e: { f: { g: { h: {}[]; }; }[]; }[]; } + + e: [ +>e : { f: { g: { h: {}[]; }; }[]; }[] +>[ { f: [ { g: { h: [ { // i: '', }, ], }, }, ], }, ] : { f: { g: { h: {}[]; }; }[]; }[] + { +>{ f: [ { g: { h: [ { // i: '', }, ], }, }, ], } : { f: { g: { h: {}[]; }; }[]; } + + f: [ +>f : { g: { h: {}[]; }; }[] +>[ { g: { h: [ { // i: '', }, ], }, }, ] : { g: { h: {}[]; }; }[] + { +>{ g: { h: [ { // i: '', }, ], }, } : { g: { h: {}[]; }; } + + g: { +>g : { h: {}[]; } +>{ h: [ { // i: '', }, ], } : { h: {}[]; } + + h: [ +>h : {}[] +>[ { // i: '', }, ] : {}[] + { +>{ // i: '', } : {} + + // i: '', + }, + ], + }, + }, + ], + }, + ], + }, + ], + }, + }, + ], +}; + +// Repro from 34619 + +const a1: string[][][][][] = [[[[[42]]]]]; +>a1 : string[][][][][] +>[[[[[42]]]]] : number[][][][][] +>[[[[42]]]] : number[][][][] +>[[[42]]] : number[][][] +>[[42]] : number[][] +>[42] : number[] +>42 : 42 + +const a2: string[][][][][][][][][][] = [[[[[[[[[[42]]]]]]]]]]; +>a2 : string[][][][][][][][][][] +>[[[[[[[[[[42]]]]]]]]]] : number[][][][][][][][][][] +>[[[[[[[[[42]]]]]]]]] : number[][][][][][][][][] +>[[[[[[[[42]]]]]]]] : number[][][][][][][][] +>[[[[[[[42]]]]]]] : number[][][][][][][] +>[[[[[[42]]]]]] : number[][][][][][] +>[[[[[42]]]]] : number[][][][][] +>[[[[42]]]] : number[][][][] +>[[[42]]] : number[][][] +>[[42]] : number[][] +>[42] : number[] +>42 : 42 + diff --git a/tests/cases/compiler/deeplyNestedCheck.ts b/tests/cases/compiler/deeplyNestedCheck.ts index 366599be96..9c04454ef4 100644 --- a/tests/cases/compiler/deeplyNestedCheck.ts +++ b/tests/cases/compiler/deeplyNestedCheck.ts @@ -7,3 +7,47 @@ interface DataSnapshot { interface Snapshot extends DataSnapshot { child>(path: U): Snapshot; } + +// Repro from 34619 + +interface A { b: B[] } +interface B { c: C } +interface C { d: D[] } +interface D { e: E[] } +interface E { f: F[] } +interface F { g: G } +interface G { h: H[] } +interface H { i: string } + +const x: A = { + b: [ + { + c: { + d: [ + { + e: [ + { + f: [ + { + g: { + h: [ + { + // i: '', + }, + ], + }, + }, + ], + }, + ], + }, + ], + }, + }, + ], +}; + +// Repro from 34619 + +const a1: string[][][][][] = [[[[[42]]]]]; +const a2: string[][][][][][][][][][] = [[[[[[[[[[42]]]]]]]]]];