File: recursiveMappedTypes.errors.txt

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (123 lines) | stat: -rw-r--r-- 5,216 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(3,6): error TS2456: Type alias 'Recurse' circularly references itself.
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(4,11): error TS2313: Type parameter 'K' has a circular constraint.
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(7,6): error TS2456: Type alias 'Recurse1' circularly references itself.
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(8,11): error TS2313: Type parameter 'K' has a circular constraint.
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(11,6): error TS2456: Type alias 'Recurse2' circularly references itself.
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(12,11): error TS2313: Type parameter 'K' has a circular constraint.
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(20,19): error TS2589: Type instantiation is excessively deep and possibly infinite.
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(73,5): error TS2502: '"each"' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(73,13): error TS2615: Type of property '"each"' circularly references itself in mapped type '{ [P in keyof ListWidget]: undefined extends ListWidget[P] ? never : P; }'.


==== tests/cases/conformance/types/mapped/recursiveMappedTypes.ts (9 errors) ====
    // Recursive mapped types simply appear empty
    
    type Recurse = {
         ~~~~~~~
!!! error TS2456: Type alias 'Recurse' circularly references itself.
        [K in keyof Recurse]: Recurse[K]
              ~~~~~~~~~~~~~
!!! error TS2313: Type parameter 'K' has a circular constraint.
    }
    
    type Recurse1 = {
         ~~~~~~~~
!!! error TS2456: Type alias 'Recurse1' circularly references itself.
        [K in keyof Recurse2]: Recurse2[K]
              ~~~~~~~~~~~~~~
!!! error TS2313: Type parameter 'K' has a circular constraint.
    }
    
    type Recurse2 = {
         ~~~~~~~~
!!! error TS2456: Type alias 'Recurse2' circularly references itself.
        [K in keyof Recurse1]: Recurse1[K]
              ~~~~~~~~~~~~~~
!!! error TS2313: Type parameter 'K' has a circular constraint.
!!! related TS2751 tests/cases/conformance/types/mapped/recursiveMappedTypes.ts:8:17: Circularity originates in type at this location.
    }
    
    // Repro from #27881
    
    export type Circular<T> = {[P in keyof T]: Circular<T>};
    type tup = [number, number, number, number];
    
    function foo(arg: Circular<tup>): tup {
                      ~~~~~~~~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
      return arg;
    }
    
    // Repro from #29442
    
    type DeepMap<T extends unknown[], R> = {
      [K in keyof T]: T[K] extends unknown[] ? DeepMap<T[K], R> : R;
    };
    
    type tpl = [string, [string, [string]]];
    type arr = string[][];
    
    type t1 = DeepMap<tpl, number>;  // [number, [number, [number]]]
    type t2 = DeepMap<arr, number>;  // number[][]
    
    // Repro from #29577
    
    type Transform<T> = { [K in keyof T]: Transform<T[K]> };
    
    interface User {
        avatar: string;
    }
    
    interface Guest {
        displayName: string;
    }
    
    interface Product {
        users: (User | Guest)[];
    }
    
    declare var product: Transform<Product>;
    product.users;  // (Transform<User> | Transform<Guest>)[]
    
    // Repro from #29702
    
    type Remap1<T> = { [P in keyof T]: Remap1<T[P]>; };
    type Remap2<T> = T extends object ? { [P in keyof T]: Remap2<T[P]>; } : T;
      
    type a = Remap1<string[]>;  // string[]
    type b = Remap2<string[]>;  // string[]
    
    // Repro from #29992
    
    type NonOptionalKeys<T> = { [P in keyof T]: undefined extends T[P] ? never : P }[keyof T];
    type Child<T> = { [P in NonOptionalKeys<T>]: T[P] }
    
    export interface ListWidget {
        "type": "list",
        "minimum_count": number,
        "maximum_count": number,
        "collapsable"?: boolean, //default to false, means all expanded
        "each": Child<ListWidget>;
        ~~~~~~
!!! error TS2502: '"each"' is referenced directly or indirectly in its own type annotation.
                ~~~~~~~~~~~~~~~~~
!!! error TS2615: Type of property '"each"' circularly references itself in mapped type '{ [P in keyof ListWidget]: undefined extends ListWidget[P] ? never : P; }'.
    }
    
    type ListChild = Child<ListWidget>
    
    declare let x: ListChild;
    x.type;
    
    // Repros from #41790
    
    export type TV<T, K extends keyof T> = T[K] extends Record<infer E, any> ? E : never;
    
    export type ObjectOrArray<T, K extends keyof any = keyof any> = T[] | Record<K, T | Record<K, T> | T[]>;
    export type ThemeValue<K extends keyof ThemeType, ThemeType, TVal = any> =
        ThemeType[K] extends TVal[] ? number :
        ThemeType[K] extends Record<infer E, TVal> ? E :
        ThemeType[K] extends ObjectOrArray<infer F> ? F : never;
    
    export type Foo<T> = T extends { [P in infer E]: any } ? E : never;