|
| 1 | +=== tests/cases/conformance/types/typeRelationships/typeInference/discriminatedUnionInference.ts === |
| 2 | +// Repro from #28862 |
| 3 | + |
| 4 | +type Foo<A> = { type: "foo", (): A[] }; |
| 5 | +>Foo : Symbol(Foo, Decl(discriminatedUnionInference.ts, 0, 0)) |
| 6 | +>A : Symbol(A, Decl(discriminatedUnionInference.ts, 2, 9)) |
| 7 | +>type : Symbol(type, Decl(discriminatedUnionInference.ts, 2, 15)) |
| 8 | +>A : Symbol(A, Decl(discriminatedUnionInference.ts, 2, 9)) |
| 9 | + |
| 10 | +type Bar<A> = { type: "bar", (): A }; |
| 11 | +>Bar : Symbol(Bar, Decl(discriminatedUnionInference.ts, 2, 39)) |
| 12 | +>A : Symbol(A, Decl(discriminatedUnionInference.ts, 3, 9)) |
| 13 | +>type : Symbol(type, Decl(discriminatedUnionInference.ts, 3, 15)) |
| 14 | +>A : Symbol(A, Decl(discriminatedUnionInference.ts, 3, 9)) |
| 15 | + |
| 16 | +type FooBar<A> = Foo<A> | Bar<A>; |
| 17 | +>FooBar : Symbol(FooBar, Decl(discriminatedUnionInference.ts, 3, 37)) |
| 18 | +>A : Symbol(A, Decl(discriminatedUnionInference.ts, 5, 12)) |
| 19 | +>Foo : Symbol(Foo, Decl(discriminatedUnionInference.ts, 0, 0)) |
| 20 | +>A : Symbol(A, Decl(discriminatedUnionInference.ts, 5, 12)) |
| 21 | +>Bar : Symbol(Bar, Decl(discriminatedUnionInference.ts, 2, 39)) |
| 22 | +>A : Symbol(A, Decl(discriminatedUnionInference.ts, 5, 12)) |
| 23 | + |
| 24 | +type InferA<T> = T extends FooBar<infer A> ? A : never; |
| 25 | +>InferA : Symbol(InferA, Decl(discriminatedUnionInference.ts, 5, 33)) |
| 26 | +>T : Symbol(T, Decl(discriminatedUnionInference.ts, 7, 12)) |
| 27 | +>T : Symbol(T, Decl(discriminatedUnionInference.ts, 7, 12)) |
| 28 | +>FooBar : Symbol(FooBar, Decl(discriminatedUnionInference.ts, 3, 37)) |
| 29 | +>A : Symbol(A, Decl(discriminatedUnionInference.ts, 7, 39)) |
| 30 | +>A : Symbol(A, Decl(discriminatedUnionInference.ts, 7, 39)) |
| 31 | + |
| 32 | +type FooA = InferA<Foo<number>>; // number |
| 33 | +>FooA : Symbol(FooA, Decl(discriminatedUnionInference.ts, 7, 55)) |
| 34 | +>InferA : Symbol(InferA, Decl(discriminatedUnionInference.ts, 5, 33)) |
| 35 | +>Foo : Symbol(Foo, Decl(discriminatedUnionInference.ts, 0, 0)) |
| 36 | + |
| 37 | +// Repro from #28862 |
| 38 | + |
| 39 | +type Item<T> = { kind: 'a', data: T } | { kind: 'b', data: T[] }; |
| 40 | +>Item : Symbol(Item, Decl(discriminatedUnionInference.ts, 9, 32)) |
| 41 | +>T : Symbol(T, Decl(discriminatedUnionInference.ts, 13, 10)) |
| 42 | +>kind : Symbol(kind, Decl(discriminatedUnionInference.ts, 13, 16)) |
| 43 | +>data : Symbol(data, Decl(discriminatedUnionInference.ts, 13, 27)) |
| 44 | +>T : Symbol(T, Decl(discriminatedUnionInference.ts, 13, 10)) |
| 45 | +>kind : Symbol(kind, Decl(discriminatedUnionInference.ts, 13, 41)) |
| 46 | +>data : Symbol(data, Decl(discriminatedUnionInference.ts, 13, 52)) |
| 47 | +>T : Symbol(T, Decl(discriminatedUnionInference.ts, 13, 10)) |
| 48 | + |
| 49 | +declare function foo<T>(item: Item<T>): T; |
| 50 | +>foo : Symbol(foo, Decl(discriminatedUnionInference.ts, 13, 65)) |
| 51 | +>T : Symbol(T, Decl(discriminatedUnionInference.ts, 15, 21)) |
| 52 | +>item : Symbol(item, Decl(discriminatedUnionInference.ts, 15, 24)) |
| 53 | +>Item : Symbol(Item, Decl(discriminatedUnionInference.ts, 9, 32)) |
| 54 | +>T : Symbol(T, Decl(discriminatedUnionInference.ts, 15, 21)) |
| 55 | +>T : Symbol(T, Decl(discriminatedUnionInference.ts, 15, 21)) |
| 56 | + |
| 57 | +let x1 = foo({ kind: 'a', data: 42 }); // number |
| 58 | +>x1 : Symbol(x1, Decl(discriminatedUnionInference.ts, 17, 3)) |
| 59 | +>foo : Symbol(foo, Decl(discriminatedUnionInference.ts, 13, 65)) |
| 60 | +>kind : Symbol(kind, Decl(discriminatedUnionInference.ts, 17, 14)) |
| 61 | +>data : Symbol(data, Decl(discriminatedUnionInference.ts, 17, 25)) |
| 62 | + |
| 63 | +let x2 = foo({ kind: 'b', data: [1, 2] }); // number |
| 64 | +>x2 : Symbol(x2, Decl(discriminatedUnionInference.ts, 18, 3)) |
| 65 | +>foo : Symbol(foo, Decl(discriminatedUnionInference.ts, 13, 65)) |
| 66 | +>kind : Symbol(kind, Decl(discriminatedUnionInference.ts, 18, 14)) |
| 67 | +>data : Symbol(data, Decl(discriminatedUnionInference.ts, 18, 25)) |
| 68 | + |
0 commit comments