diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/discriminatedUnionInference.ts b/tests/cases/conformance/types/typeRelationships/typeInference/discriminatedUnionInference.ts new file mode 100644 index 00000000000..8009ae23537 --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/typeInference/discriminatedUnionInference.ts @@ -0,0 +1,21 @@ +// @strict: true + +// Repro from #28862 + +type Foo = { type: "foo", (): A[] }; +type Bar = { type: "bar", (): A }; + +type FooBar = Foo | Bar; + +type InferA = T extends FooBar ? A : never; + +type FooA = InferA>; // number + +// Repro from #28862 + +type Item = { kind: 'a', data: T } | { kind: 'b', data: T[] }; + +declare function foo(item: Item): T; + +let x1 = foo({ kind: 'a', data: 42 }); // number +let x2 = foo({ kind: 'b', data: [1, 2] }); // number