|
| 1 | +=== tests/cases/compiler/genericFunctionsAndConditionalInference.ts === |
| 2 | +type Boxified<T> = { [P in keyof T]: { value: T[P]} }; |
| 3 | +>Boxified : Symbol(Boxified, Decl(genericFunctionsAndConditionalInference.ts, 0, 0)) |
| 4 | +>T : Symbol(T, Decl(genericFunctionsAndConditionalInference.ts, 0, 14)) |
| 5 | +>P : Symbol(P, Decl(genericFunctionsAndConditionalInference.ts, 0, 22)) |
| 6 | +>T : Symbol(T, Decl(genericFunctionsAndConditionalInference.ts, 0, 14)) |
| 7 | +>value : Symbol(value, Decl(genericFunctionsAndConditionalInference.ts, 0, 38)) |
| 8 | +>T : Symbol(T, Decl(genericFunctionsAndConditionalInference.ts, 0, 14)) |
| 9 | +>P : Symbol(P, Decl(genericFunctionsAndConditionalInference.ts, 0, 22)) |
| 10 | + |
| 11 | +declare function unboxify<T>(obj: Boxified<T>): T; |
| 12 | +>unboxify : Symbol(unboxify, Decl(genericFunctionsAndConditionalInference.ts, 0, 54)) |
| 13 | +>T : Symbol(T, Decl(genericFunctionsAndConditionalInference.ts, 2, 26)) |
| 14 | +>obj : Symbol(obj, Decl(genericFunctionsAndConditionalInference.ts, 2, 29)) |
| 15 | +>Boxified : Symbol(Boxified, Decl(genericFunctionsAndConditionalInference.ts, 0, 0)) |
| 16 | +>T : Symbol(T, Decl(genericFunctionsAndConditionalInference.ts, 2, 26)) |
| 17 | +>T : Symbol(T, Decl(genericFunctionsAndConditionalInference.ts, 2, 26)) |
| 18 | + |
| 19 | +function foo<U, V>(obj: { u: { value: U }, v: { value: V } }) { |
| 20 | +>foo : Symbol(foo, Decl(genericFunctionsAndConditionalInference.ts, 2, 50)) |
| 21 | +>U : Symbol(U, Decl(genericFunctionsAndConditionalInference.ts, 4, 13)) |
| 22 | +>V : Symbol(V, Decl(genericFunctionsAndConditionalInference.ts, 4, 15)) |
| 23 | +>obj : Symbol(obj, Decl(genericFunctionsAndConditionalInference.ts, 4, 19)) |
| 24 | +>u : Symbol(u, Decl(genericFunctionsAndConditionalInference.ts, 4, 25)) |
| 25 | +>value : Symbol(value, Decl(genericFunctionsAndConditionalInference.ts, 4, 30)) |
| 26 | +>U : Symbol(U, Decl(genericFunctionsAndConditionalInference.ts, 4, 13)) |
| 27 | +>v : Symbol(v, Decl(genericFunctionsAndConditionalInference.ts, 4, 42)) |
| 28 | +>value : Symbol(value, Decl(genericFunctionsAndConditionalInference.ts, 4, 47)) |
| 29 | +>V : Symbol(V, Decl(genericFunctionsAndConditionalInference.ts, 4, 15)) |
| 30 | + |
| 31 | + return unboxify(obj); |
| 32 | +>unboxify : Symbol(unboxify, Decl(genericFunctionsAndConditionalInference.ts, 0, 54)) |
| 33 | +>obj : Symbol(obj, Decl(genericFunctionsAndConditionalInference.ts, 4, 19)) |
| 34 | +} |
| 35 | + |
| 36 | +let qq = foo({ u: { value: 10 }, v: { value: 'hello'} }); // { u: U, v: V } but should be { u: number, v: string } |
| 37 | +>qq : Symbol(qq, Decl(genericFunctionsAndConditionalInference.ts, 8, 3)) |
| 38 | +>foo : Symbol(foo, Decl(genericFunctionsAndConditionalInference.ts, 2, 50)) |
| 39 | +>u : Symbol(u, Decl(genericFunctionsAndConditionalInference.ts, 8, 14)) |
| 40 | +>value : Symbol(value, Decl(genericFunctionsAndConditionalInference.ts, 8, 19)) |
| 41 | +>v : Symbol(v, Decl(genericFunctionsAndConditionalInference.ts, 8, 32)) |
| 42 | +>value : Symbol(value, Decl(genericFunctionsAndConditionalInference.ts, 8, 37)) |
| 43 | + |
| 44 | +// From #42385 |
| 45 | +interface Targets<A> { |
| 46 | +>Targets : Symbol(Targets, Decl(genericFunctionsAndConditionalInference.ts, 8, 57)) |
| 47 | +>A : Symbol(A, Decl(genericFunctionsAndConditionalInference.ts, 11, 18)) |
| 48 | + |
| 49 | + left: A |
| 50 | +>left : Symbol(Targets.left, Decl(genericFunctionsAndConditionalInference.ts, 11, 22)) |
| 51 | +>A : Symbol(A, Decl(genericFunctionsAndConditionalInference.ts, 11, 18)) |
| 52 | + |
| 53 | + right: A |
| 54 | +>right : Symbol(Targets.right, Decl(genericFunctionsAndConditionalInference.ts, 12, 11)) |
| 55 | +>A : Symbol(A, Decl(genericFunctionsAndConditionalInference.ts, 11, 18)) |
| 56 | +} |
| 57 | +type Target = keyof Targets<any> |
| 58 | +>Target : Symbol(Target, Decl(genericFunctionsAndConditionalInference.ts, 14, 1)) |
| 59 | +>Targets : Symbol(Targets, Decl(genericFunctionsAndConditionalInference.ts, 8, 57)) |
| 60 | + |
| 61 | +type Result<F extends Target, A> = Targets<A>[F] |
| 62 | +>Result : Symbol(Result, Decl(genericFunctionsAndConditionalInference.ts, 15, 32)) |
| 63 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 16, 12)) |
| 64 | +>Target : Symbol(Target, Decl(genericFunctionsAndConditionalInference.ts, 14, 1)) |
| 65 | +>A : Symbol(A, Decl(genericFunctionsAndConditionalInference.ts, 16, 29)) |
| 66 | +>Targets : Symbol(Targets, Decl(genericFunctionsAndConditionalInference.ts, 8, 57)) |
| 67 | +>A : Symbol(A, Decl(genericFunctionsAndConditionalInference.ts, 16, 29)) |
| 68 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 16, 12)) |
| 69 | + |
| 70 | +type LR<F extends Target, L, R> = [F] extends ["left"] ? L : R |
| 71 | +>LR : Symbol(LR, Decl(genericFunctionsAndConditionalInference.ts, 16, 48)) |
| 72 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 18, 8)) |
| 73 | +>Target : Symbol(Target, Decl(genericFunctionsAndConditionalInference.ts, 14, 1)) |
| 74 | +>L : Symbol(L, Decl(genericFunctionsAndConditionalInference.ts, 18, 25)) |
| 75 | +>R : Symbol(R, Decl(genericFunctionsAndConditionalInference.ts, 18, 28)) |
| 76 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 18, 8)) |
| 77 | +>L : Symbol(L, Decl(genericFunctionsAndConditionalInference.ts, 18, 25)) |
| 78 | +>R : Symbol(R, Decl(genericFunctionsAndConditionalInference.ts, 18, 28)) |
| 79 | + |
| 80 | +interface Ops<F extends Target> { |
| 81 | +>Ops : Symbol(Ops, Decl(genericFunctionsAndConditionalInference.ts, 18, 62)) |
| 82 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 20, 14)) |
| 83 | +>Target : Symbol(Target, Decl(genericFunctionsAndConditionalInference.ts, 14, 1)) |
| 84 | + |
| 85 | + _f: F |
| 86 | +>_f : Symbol(Ops._f, Decl(genericFunctionsAndConditionalInference.ts, 20, 33)) |
| 87 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 20, 14)) |
| 88 | + |
| 89 | + str: Result<F, string> |
| 90 | +>str : Symbol(Ops.str, Decl(genericFunctionsAndConditionalInference.ts, 21, 9)) |
| 91 | +>Result : Symbol(Result, Decl(genericFunctionsAndConditionalInference.ts, 15, 32)) |
| 92 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 20, 14)) |
| 93 | + |
| 94 | + num: Result<F, number> |
| 95 | +>num : Symbol(Ops.num, Decl(genericFunctionsAndConditionalInference.ts, 22, 26)) |
| 96 | +>Result : Symbol(Result, Decl(genericFunctionsAndConditionalInference.ts, 15, 32)) |
| 97 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 20, 14)) |
| 98 | + |
| 99 | + lr<I, O>(a: Result<F, I>, o: Result<F, O>): Result<F, LR<F, I, O>> |
| 100 | +>lr : Symbol(Ops.lr, Decl(genericFunctionsAndConditionalInference.ts, 23, 26)) |
| 101 | +>I : Symbol(I, Decl(genericFunctionsAndConditionalInference.ts, 24, 7)) |
| 102 | +>O : Symbol(O, Decl(genericFunctionsAndConditionalInference.ts, 24, 9)) |
| 103 | +>a : Symbol(a, Decl(genericFunctionsAndConditionalInference.ts, 24, 13)) |
| 104 | +>Result : Symbol(Result, Decl(genericFunctionsAndConditionalInference.ts, 15, 32)) |
| 105 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 20, 14)) |
| 106 | +>I : Symbol(I, Decl(genericFunctionsAndConditionalInference.ts, 24, 7)) |
| 107 | +>o : Symbol(o, Decl(genericFunctionsAndConditionalInference.ts, 24, 29)) |
| 108 | +>Result : Symbol(Result, Decl(genericFunctionsAndConditionalInference.ts, 15, 32)) |
| 109 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 20, 14)) |
| 110 | +>O : Symbol(O, Decl(genericFunctionsAndConditionalInference.ts, 24, 9)) |
| 111 | +>Result : Symbol(Result, Decl(genericFunctionsAndConditionalInference.ts, 15, 32)) |
| 112 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 20, 14)) |
| 113 | +>LR : Symbol(LR, Decl(genericFunctionsAndConditionalInference.ts, 16, 48)) |
| 114 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 20, 14)) |
| 115 | +>I : Symbol(I, Decl(genericFunctionsAndConditionalInference.ts, 24, 7)) |
| 116 | +>O : Symbol(O, Decl(genericFunctionsAndConditionalInference.ts, 24, 9)) |
| 117 | + |
| 118 | + dict: <P>(p: {[k in keyof P]: Result<F, P[k]>}) => Result<F, P> |
| 119 | +>dict : Symbol(Ops.dict, Decl(genericFunctionsAndConditionalInference.ts, 24, 70)) |
| 120 | +>P : Symbol(P, Decl(genericFunctionsAndConditionalInference.ts, 25, 11)) |
| 121 | +>p : Symbol(p, Decl(genericFunctionsAndConditionalInference.ts, 25, 14)) |
| 122 | +>k : Symbol(k, Decl(genericFunctionsAndConditionalInference.ts, 25, 19)) |
| 123 | +>P : Symbol(P, Decl(genericFunctionsAndConditionalInference.ts, 25, 11)) |
| 124 | +>Result : Symbol(Result, Decl(genericFunctionsAndConditionalInference.ts, 15, 32)) |
| 125 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 20, 14)) |
| 126 | +>P : Symbol(P, Decl(genericFunctionsAndConditionalInference.ts, 25, 11)) |
| 127 | +>k : Symbol(k, Decl(genericFunctionsAndConditionalInference.ts, 25, 19)) |
| 128 | +>Result : Symbol(Result, Decl(genericFunctionsAndConditionalInference.ts, 15, 32)) |
| 129 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 20, 14)) |
| 130 | +>P : Symbol(P, Decl(genericFunctionsAndConditionalInference.ts, 25, 11)) |
| 131 | +} |
| 132 | +const left: Ops<"left"> = {} as any |
| 133 | +>left : Symbol(left, Decl(genericFunctionsAndConditionalInference.ts, 27, 5)) |
| 134 | +>Ops : Symbol(Ops, Decl(genericFunctionsAndConditionalInference.ts, 18, 62)) |
| 135 | + |
| 136 | +const right: Ops<"right"> = {} as any |
| 137 | +>right : Symbol(right, Decl(genericFunctionsAndConditionalInference.ts, 28, 5)) |
| 138 | +>Ops : Symbol(Ops, Decl(genericFunctionsAndConditionalInference.ts, 18, 62)) |
| 139 | + |
| 140 | +const ok = <F extends Target>(at: Ops<F>) => ({lr: at.lr(at.str, at.num)}) |
| 141 | +>ok : Symbol(ok, Decl(genericFunctionsAndConditionalInference.ts, 30, 5)) |
| 142 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 30, 12)) |
| 143 | +>Target : Symbol(Target, Decl(genericFunctionsAndConditionalInference.ts, 14, 1)) |
| 144 | +>at : Symbol(at, Decl(genericFunctionsAndConditionalInference.ts, 30, 30)) |
| 145 | +>Ops : Symbol(Ops, Decl(genericFunctionsAndConditionalInference.ts, 18, 62)) |
| 146 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 30, 12)) |
| 147 | +>lr : Symbol(lr, Decl(genericFunctionsAndConditionalInference.ts, 30, 47)) |
| 148 | +>at.lr : Symbol(Ops.lr, Decl(genericFunctionsAndConditionalInference.ts, 23, 26)) |
| 149 | +>at : Symbol(at, Decl(genericFunctionsAndConditionalInference.ts, 30, 30)) |
| 150 | +>lr : Symbol(Ops.lr, Decl(genericFunctionsAndConditionalInference.ts, 23, 26)) |
| 151 | +>at.str : Symbol(Ops.str, Decl(genericFunctionsAndConditionalInference.ts, 21, 9)) |
| 152 | +>at : Symbol(at, Decl(genericFunctionsAndConditionalInference.ts, 30, 30)) |
| 153 | +>str : Symbol(Ops.str, Decl(genericFunctionsAndConditionalInference.ts, 21, 9)) |
| 154 | +>at.num : Symbol(Ops.num, Decl(genericFunctionsAndConditionalInference.ts, 22, 26)) |
| 155 | +>at : Symbol(at, Decl(genericFunctionsAndConditionalInference.ts, 30, 30)) |
| 156 | +>num : Symbol(Ops.num, Decl(genericFunctionsAndConditionalInference.ts, 22, 26)) |
| 157 | + |
| 158 | +const orphaned = <F extends Target>(at: Ops<F>) => at.dict(ok(at)) |
| 159 | +>orphaned : Symbol(orphaned, Decl(genericFunctionsAndConditionalInference.ts, 31, 5)) |
| 160 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 31, 18)) |
| 161 | +>Target : Symbol(Target, Decl(genericFunctionsAndConditionalInference.ts, 14, 1)) |
| 162 | +>at : Symbol(at, Decl(genericFunctionsAndConditionalInference.ts, 31, 36)) |
| 163 | +>Ops : Symbol(Ops, Decl(genericFunctionsAndConditionalInference.ts, 18, 62)) |
| 164 | +>F : Symbol(F, Decl(genericFunctionsAndConditionalInference.ts, 31, 18)) |
| 165 | +>at.dict : Symbol(Ops.dict, Decl(genericFunctionsAndConditionalInference.ts, 24, 70)) |
| 166 | +>at : Symbol(at, Decl(genericFunctionsAndConditionalInference.ts, 31, 36)) |
| 167 | +>dict : Symbol(Ops.dict, Decl(genericFunctionsAndConditionalInference.ts, 24, 70)) |
| 168 | +>ok : Symbol(ok, Decl(genericFunctionsAndConditionalInference.ts, 30, 5)) |
| 169 | +>at : Symbol(at, Decl(genericFunctionsAndConditionalInference.ts, 31, 36)) |
| 170 | + |
| 171 | +const leftOk = ok(left) |
| 172 | +>leftOk : Symbol(leftOk, Decl(genericFunctionsAndConditionalInference.ts, 33, 5)) |
| 173 | +>ok : Symbol(ok, Decl(genericFunctionsAndConditionalInference.ts, 30, 5)) |
| 174 | +>left : Symbol(left, Decl(genericFunctionsAndConditionalInference.ts, 27, 5)) |
| 175 | + |
| 176 | +const leftOrphaned = orphaned(left) |
| 177 | +>leftOrphaned : Symbol(leftOrphaned, Decl(genericFunctionsAndConditionalInference.ts, 34, 5)) |
| 178 | +>orphaned : Symbol(orphaned, Decl(genericFunctionsAndConditionalInference.ts, 31, 5)) |
| 179 | +>left : Symbol(left, Decl(genericFunctionsAndConditionalInference.ts, 27, 5)) |
| 180 | + |
| 181 | +const rightOk = ok(right) |
| 182 | +>rightOk : Symbol(rightOk, Decl(genericFunctionsAndConditionalInference.ts, 36, 5)) |
| 183 | +>ok : Symbol(ok, Decl(genericFunctionsAndConditionalInference.ts, 30, 5)) |
| 184 | +>right : Symbol(right, Decl(genericFunctionsAndConditionalInference.ts, 28, 5)) |
| 185 | + |
| 186 | +const rightOrphaned = orphaned(right) |
| 187 | +>rightOrphaned : Symbol(rightOrphaned, Decl(genericFunctionsAndConditionalInference.ts, 37, 5)) |
| 188 | +>orphaned : Symbol(orphaned, Decl(genericFunctionsAndConditionalInference.ts, 31, 5)) |
| 189 | +>right : Symbol(right, Decl(genericFunctionsAndConditionalInference.ts, 28, 5)) |
| 190 | + |
0 commit comments