From 4ae0848bd4acc1e26b97ca39bd2c3fae4ed08ac3 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 5 Dec 2018 15:20:21 -0800 Subject: [PATCH] Add tests --- .../discriminatedUnionInference.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/cases/conformance/types/typeRelationships/typeInference/discriminatedUnionInference.ts 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