From 6b61422e077c531f0f8bebad9c8b6b45ab93a004 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 2 Nov 2014 11:14:23 -0800 Subject: [PATCH] Adding tests --- .../typeInference/unionTypeInference.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts b/tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts new file mode 100644 index 00000000000..a4b5edba9eb --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts @@ -0,0 +1,20 @@ +// Verify that inferences made *to* a type parameter in a union type are secondary +// to inferences made directly to that type parameter + +function f(x: T, y: string|T): T { + return x; +} +function g(value: [string, T]): T { + return value[1]; +} + +var a: number; +var a = f(1, 2); +var b: number; +var b = f(1, "hello"); +var c: number; +var c = f(1, a || "hello"); +var d: any; +var d = f(undefined, "abc"); +var e: boolean; +var e = g(["string", true]);