From 346253a0d520e24083ab013d247b986cc9b63db9 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 13 Nov 2015 11:13:10 -0800 Subject: [PATCH] test, first pass at a fix --- src/compiler/checker.ts | 4 +++ .../typeGuards/typeGuardTypeOfUndefined.ts | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/cases/conformance/expressions/typeGuards/typeGuardTypeOfUndefined.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ec91b255ae6..6f5a3e67d0a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -200,6 +200,10 @@ namespace ts { "symbol": { type: esSymbolType, flags: TypeFlags.ESSymbol + }, + "undefined": { + type: undefinedType, + flags: TypeFlags.ContainsUndefinedOrNull } }; diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardTypeOfUndefined.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardTypeOfUndefined.ts new file mode 100644 index 00000000000..50612449145 --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardTypeOfUndefined.ts @@ -0,0 +1,28 @@ +// undefined type guard adds no new type information +function test1(a: any) { + if (typeof a !== "undefined") { + if (typeof a === "boolean") { + a; + } + } +} + +function test2(a: any) { + if (typeof a === "undefined") { + if (typeof a === "boolean") { + a; + } + } +} + +function test3(a: any) { + if (typeof a === "undefined" || typeof a === "boolean") { + a; + } +} + +function test4(a: any) { + if (typeof a !== "undefined" && typeof a === "boolean") { + a; + } +}