|
| 1 | +=== tests/cases/compiler/mappedTypeGenericIndexedAccess.ts === |
| 2 | +// Repro from #49242 |
| 3 | + |
| 4 | +type Types = { |
| 5 | +>Types : Symbol(Types, Decl(mappedTypeGenericIndexedAccess.ts, 0, 0)) |
| 6 | + |
| 7 | + first: { a1: true }; |
| 8 | +>first : Symbol(first, Decl(mappedTypeGenericIndexedAccess.ts, 2, 14)) |
| 9 | +>a1 : Symbol(a1, Decl(mappedTypeGenericIndexedAccess.ts, 3, 12)) |
| 10 | + |
| 11 | + second: { a2: true }; |
| 12 | +>second : Symbol(second, Decl(mappedTypeGenericIndexedAccess.ts, 3, 24)) |
| 13 | +>a2 : Symbol(a2, Decl(mappedTypeGenericIndexedAccess.ts, 4, 13)) |
| 14 | + |
| 15 | + third: { a3: true }; |
| 16 | +>third : Symbol(third, Decl(mappedTypeGenericIndexedAccess.ts, 4, 25)) |
| 17 | +>a3 : Symbol(a3, Decl(mappedTypeGenericIndexedAccess.ts, 5, 12)) |
| 18 | +} |
| 19 | + |
| 20 | +class Test { |
| 21 | +>Test : Symbol(Test, Decl(mappedTypeGenericIndexedAccess.ts, 6, 1)) |
| 22 | + |
| 23 | + entries: { [T in keyof Types]?: Types[T][] }; |
| 24 | +>entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) |
| 25 | +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 9, 16)) |
| 26 | +>Types : Symbol(Types, Decl(mappedTypeGenericIndexedAccess.ts, 0, 0)) |
| 27 | +>Types : Symbol(Types, Decl(mappedTypeGenericIndexedAccess.ts, 0, 0)) |
| 28 | +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 9, 16)) |
| 29 | + |
| 30 | + constructor() { |
| 31 | + this.entries = {}; |
| 32 | +>this.entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) |
| 33 | +>this : Symbol(Test, Decl(mappedTypeGenericIndexedAccess.ts, 6, 1)) |
| 34 | +>entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) |
| 35 | + } |
| 36 | + |
| 37 | + addEntry<T extends keyof Types>(name: T, entry: Types[T]) { |
| 38 | +>addEntry : Symbol(Test.addEntry, Decl(mappedTypeGenericIndexedAccess.ts, 13, 5)) |
| 39 | +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 15, 13)) |
| 40 | +>Types : Symbol(Types, Decl(mappedTypeGenericIndexedAccess.ts, 0, 0)) |
| 41 | +>name : Symbol(name, Decl(mappedTypeGenericIndexedAccess.ts, 15, 36)) |
| 42 | +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 15, 13)) |
| 43 | +>entry : Symbol(entry, Decl(mappedTypeGenericIndexedAccess.ts, 15, 44)) |
| 44 | +>Types : Symbol(Types, Decl(mappedTypeGenericIndexedAccess.ts, 0, 0)) |
| 45 | +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 15, 13)) |
| 46 | + |
| 47 | + if (!this.entries[name]) { |
| 48 | +>this.entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) |
| 49 | +>this : Symbol(Test, Decl(mappedTypeGenericIndexedAccess.ts, 6, 1)) |
| 50 | +>entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) |
| 51 | +>name : Symbol(name, Decl(mappedTypeGenericIndexedAccess.ts, 15, 36)) |
| 52 | + |
| 53 | + this.entries[name] = []; |
| 54 | +>this.entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) |
| 55 | +>this : Symbol(Test, Decl(mappedTypeGenericIndexedAccess.ts, 6, 1)) |
| 56 | +>entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) |
| 57 | +>name : Symbol(name, Decl(mappedTypeGenericIndexedAccess.ts, 15, 36)) |
| 58 | + } |
| 59 | + this.entries[name]?.push(entry); |
| 60 | +>this.entries[name]?.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) |
| 61 | +>this.entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) |
| 62 | +>this : Symbol(Test, Decl(mappedTypeGenericIndexedAccess.ts, 6, 1)) |
| 63 | +>entries : Symbol(Test.entries, Decl(mappedTypeGenericIndexedAccess.ts, 8, 12)) |
| 64 | +>name : Symbol(name, Decl(mappedTypeGenericIndexedAccess.ts, 15, 36)) |
| 65 | +>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) |
| 66 | +>entry : Symbol(entry, Decl(mappedTypeGenericIndexedAccess.ts, 15, 44)) |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +// Repro from #49338 |
| 71 | + |
| 72 | +type TypesMap = { |
| 73 | +>TypesMap : Symbol(TypesMap, Decl(mappedTypeGenericIndexedAccess.ts, 21, 1)) |
| 74 | + |
| 75 | + [0]: { foo: 'bar'; }; |
| 76 | +>[0] : Symbol([0], Decl(mappedTypeGenericIndexedAccess.ts, 25, 17)) |
| 77 | +>0 : Symbol([0], Decl(mappedTypeGenericIndexedAccess.ts, 25, 17)) |
| 78 | +>foo : Symbol(foo, Decl(mappedTypeGenericIndexedAccess.ts, 26, 10)) |
| 79 | + |
| 80 | + [1]: { a: 'b'; }; |
| 81 | +>[1] : Symbol([1], Decl(mappedTypeGenericIndexedAccess.ts, 26, 25)) |
| 82 | +>1 : Symbol([1], Decl(mappedTypeGenericIndexedAccess.ts, 26, 25)) |
| 83 | +>a : Symbol(a, Decl(mappedTypeGenericIndexedAccess.ts, 27, 10)) |
| 84 | + |
| 85 | +}; |
| 86 | + |
| 87 | +type P<T extends keyof TypesMap> = { t: T; } & TypesMap[T]; |
| 88 | +>P : Symbol(P, Decl(mappedTypeGenericIndexedAccess.ts, 28, 2)) |
| 89 | +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 30, 7)) |
| 90 | +>TypesMap : Symbol(TypesMap, Decl(mappedTypeGenericIndexedAccess.ts, 21, 1)) |
| 91 | +>t : Symbol(t, Decl(mappedTypeGenericIndexedAccess.ts, 30, 36)) |
| 92 | +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 30, 7)) |
| 93 | +>TypesMap : Symbol(TypesMap, Decl(mappedTypeGenericIndexedAccess.ts, 21, 1)) |
| 94 | +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 30, 7)) |
| 95 | + |
| 96 | +type TypeHandlers = { |
| 97 | +>TypeHandlers : Symbol(TypeHandlers, Decl(mappedTypeGenericIndexedAccess.ts, 30, 59)) |
| 98 | + |
| 99 | + [T in keyof TypesMap]?: (p: P<T>) => void; |
| 100 | +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 33, 5)) |
| 101 | +>TypesMap : Symbol(TypesMap, Decl(mappedTypeGenericIndexedAccess.ts, 21, 1)) |
| 102 | +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 33, 29)) |
| 103 | +>P : Symbol(P, Decl(mappedTypeGenericIndexedAccess.ts, 28, 2)) |
| 104 | +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 33, 5)) |
| 105 | + |
| 106 | +}; |
| 107 | + |
| 108 | +const typeHandlers: TypeHandlers = { |
| 109 | +>typeHandlers : Symbol(typeHandlers, Decl(mappedTypeGenericIndexedAccess.ts, 36, 5)) |
| 110 | +>TypeHandlers : Symbol(TypeHandlers, Decl(mappedTypeGenericIndexedAccess.ts, 30, 59)) |
| 111 | + |
| 112 | + [0]: (p) => console.log(p.foo), |
| 113 | +>[0] : Symbol([0], Decl(mappedTypeGenericIndexedAccess.ts, 36, 36)) |
| 114 | +>0 : Symbol([0], Decl(mappedTypeGenericIndexedAccess.ts, 36, 36)) |
| 115 | +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 37, 10)) |
| 116 | +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 117 | +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) |
| 118 | +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 119 | +>p.foo : Symbol(foo, Decl(mappedTypeGenericIndexedAccess.ts, 26, 10)) |
| 120 | +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 37, 10)) |
| 121 | +>foo : Symbol(foo, Decl(mappedTypeGenericIndexedAccess.ts, 26, 10)) |
| 122 | + |
| 123 | + [1]: (p) => console.log(p.a), |
| 124 | +>[1] : Symbol([1], Decl(mappedTypeGenericIndexedAccess.ts, 37, 35)) |
| 125 | +>1 : Symbol([1], Decl(mappedTypeGenericIndexedAccess.ts, 37, 35)) |
| 126 | +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 38, 10)) |
| 127 | +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 128 | +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) |
| 129 | +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 130 | +>p.a : Symbol(a, Decl(mappedTypeGenericIndexedAccess.ts, 27, 10)) |
| 131 | +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 38, 10)) |
| 132 | +>a : Symbol(a, Decl(mappedTypeGenericIndexedAccess.ts, 27, 10)) |
| 133 | + |
| 134 | +}; |
| 135 | + |
| 136 | +const onSomeEvent = <T extends keyof TypesMap>(p: P<T>) => |
| 137 | +>onSomeEvent : Symbol(onSomeEvent, Decl(mappedTypeGenericIndexedAccess.ts, 41, 5)) |
| 138 | +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 41, 21)) |
| 139 | +>TypesMap : Symbol(TypesMap, Decl(mappedTypeGenericIndexedAccess.ts, 21, 1)) |
| 140 | +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 41, 47)) |
| 141 | +>P : Symbol(P, Decl(mappedTypeGenericIndexedAccess.ts, 28, 2)) |
| 142 | +>T : Symbol(T, Decl(mappedTypeGenericIndexedAccess.ts, 41, 21)) |
| 143 | + |
| 144 | + typeHandlers[p.t]?.(p); |
| 145 | +>typeHandlers : Symbol(typeHandlers, Decl(mappedTypeGenericIndexedAccess.ts, 36, 5)) |
| 146 | +>p.t : Symbol(t, Decl(mappedTypeGenericIndexedAccess.ts, 30, 36)) |
| 147 | +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 41, 47)) |
| 148 | +>t : Symbol(t, Decl(mappedTypeGenericIndexedAccess.ts, 30, 36)) |
| 149 | +>p : Symbol(p, Decl(mappedTypeGenericIndexedAccess.ts, 41, 47)) |
| 150 | + |
0 commit comments