|
| 1 | +=== tests/cases/compiler/typeInferenceOnIndexUnion.ts === |
| 2 | +type Options = { k: "a", a: number } | { k: "b", b: string }; |
| 3 | +>Options : Symbol(Options, Decl(typeInferenceOnIndexUnion.ts, 0, 0)) |
| 4 | +>k : Symbol(k, Decl(typeInferenceOnIndexUnion.ts, 0, 16)) |
| 5 | +>a : Symbol(a, Decl(typeInferenceOnIndexUnion.ts, 0, 24)) |
| 6 | +>k : Symbol(k, Decl(typeInferenceOnIndexUnion.ts, 0, 40)) |
| 7 | +>b : Symbol(b, Decl(typeInferenceOnIndexUnion.ts, 0, 48)) |
| 8 | + |
| 9 | +declare function f<T extends Options>(p: T["k"]): T; |
| 10 | +>f : Symbol(f, Decl(typeInferenceOnIndexUnion.ts, 0, 61)) |
| 11 | +>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 1, 19)) |
| 12 | +>Options : Symbol(Options, Decl(typeInferenceOnIndexUnion.ts, 0, 0)) |
| 13 | +>p : Symbol(p, Decl(typeInferenceOnIndexUnion.ts, 1, 38)) |
| 14 | +>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 1, 19)) |
| 15 | +>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 1, 19)) |
| 16 | + |
| 17 | +const x = f("a"); // expect it to be `{ k: "a", a: number }` |
| 18 | +>x : Symbol(x, Decl(typeInferenceOnIndexUnion.ts, 2, 5)) |
| 19 | +>f : Symbol(f, Decl(typeInferenceOnIndexUnion.ts, 0, 61)) |
| 20 | + |
| 21 | +type Options2 = { k: "a", a: number, c: {} } | { k: "b", b: string, c: {} }; |
| 22 | +>Options2 : Symbol(Options2, Decl(typeInferenceOnIndexUnion.ts, 2, 17)) |
| 23 | +>k : Symbol(k, Decl(typeInferenceOnIndexUnion.ts, 4, 17)) |
| 24 | +>a : Symbol(a, Decl(typeInferenceOnIndexUnion.ts, 4, 25)) |
| 25 | +>c : Symbol(c, Decl(typeInferenceOnIndexUnion.ts, 4, 36)) |
| 26 | +>k : Symbol(k, Decl(typeInferenceOnIndexUnion.ts, 4, 48)) |
| 27 | +>b : Symbol(b, Decl(typeInferenceOnIndexUnion.ts, 4, 56)) |
| 28 | +>c : Symbol(c, Decl(typeInferenceOnIndexUnion.ts, 4, 67)) |
| 29 | + |
| 30 | +declare function f2<T extends Options2>(p: T["k"], c: T["c"]): T; |
| 31 | +>f2 : Symbol(f2, Decl(typeInferenceOnIndexUnion.ts, 4, 76)) |
| 32 | +>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 5, 20)) |
| 33 | +>Options2 : Symbol(Options2, Decl(typeInferenceOnIndexUnion.ts, 2, 17)) |
| 34 | +>p : Symbol(p, Decl(typeInferenceOnIndexUnion.ts, 5, 40)) |
| 35 | +>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 5, 20)) |
| 36 | +>c : Symbol(c, Decl(typeInferenceOnIndexUnion.ts, 5, 50)) |
| 37 | +>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 5, 20)) |
| 38 | +>T : Symbol(T, Decl(typeInferenceOnIndexUnion.ts, 5, 20)) |
| 39 | + |
| 40 | +const x2 = f2("a", { x: 1, y: 2 }); // expect it to be `{ k: "a", a: number, c: {x: number, y: number} }` |
| 41 | +>x2 : Symbol(x2, Decl(typeInferenceOnIndexUnion.ts, 6, 5)) |
| 42 | +>f2 : Symbol(f2, Decl(typeInferenceOnIndexUnion.ts, 4, 76)) |
| 43 | +>x : Symbol(x, Decl(typeInferenceOnIndexUnion.ts, 6, 20)) |
| 44 | +>y : Symbol(y, Decl(typeInferenceOnIndexUnion.ts, 6, 26)) |
| 45 | + |
0 commit comments