From 3d153e2ac3829c03e50d921427821ea738bd8c11 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 19 Nov 2017 09:50:45 -0800 Subject: [PATCH] Add tests --- .../narrowingConstrainedTypeVariable.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/cases/conformance/types/typeRelationships/instanceOf/narrowingConstrainedTypeVariable.ts diff --git a/tests/cases/conformance/types/typeRelationships/instanceOf/narrowingConstrainedTypeVariable.ts b/tests/cases/conformance/types/typeRelationships/instanceOf/narrowingConstrainedTypeVariable.ts new file mode 100644 index 0000000000..13cc8da68c --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/instanceOf/narrowingConstrainedTypeVariable.ts @@ -0,0 +1,36 @@ +// @strict: true + +// Repro from #20138 + +class C { } + +function f1(v: T | string): void { + if (v instanceof C) { + const x: T = v; + } + else { + const s: string = v; + } +} + +class D { } + +function f2(v: T | U) { + if (v instanceof C) { + const x: T = v; + } + else { + const y: U = v; + } +} + +class E { x: string } + +function f3(v: T | { x: string }) { + if (v instanceof E) { + const x: T = v; + } + else { + const y: { x: string } = v; + } +}