From d22f4fb513cab8acc9c340d358f1112f098e6b8a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 30 Dec 2016 12:14:31 -0500 Subject: [PATCH] Added a test. --- .../narrowingGenericTypeFromInstanceof01.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/cases/conformance/types/typeRelationships/instanceOf/narrowingGenericTypeFromInstanceof01.ts diff --git a/tests/cases/conformance/types/typeRelationships/instanceOf/narrowingGenericTypeFromInstanceof01.ts b/tests/cases/conformance/types/typeRelationships/instanceOf/narrowingGenericTypeFromInstanceof01.ts new file mode 100644 index 00000000000..0209d7d3ccf --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/instanceOf/narrowingGenericTypeFromInstanceof01.ts @@ -0,0 +1,27 @@ +class A { + constructor(private a: string) { } +} + +class B { +} + +function acceptA(a: A) { } +function acceptB(b: B) { } + +function test(x: A | B) { + if (x instanceof B) { + acceptA(x); + } + + if (x instanceof A) { + acceptA(x); + } + + if (x instanceof B) { + acceptB(x); + } + + if (x instanceof B) { + acceptB(x); + } +} \ No newline at end of file