diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 00990f0c8a..ca3c027640 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4720,7 +4720,7 @@ module ts { return targetType; } // If current type is a union type, remove all constituents that aren't subtypes of target type - if (type.flags && TypeFlags.Union) { + if (type.flags & TypeFlags.Union) { return getUnionType(filter((type).types, t => isTypeSubtypeOf(t, targetType))); } return type; diff --git a/tests/baselines/reference/typeGuardsWithInstanceOf.js b/tests/baselines/reference/typeGuardsWithInstanceOf.js new file mode 100644 index 0000000000..34af7037f0 --- /dev/null +++ b/tests/baselines/reference/typeGuardsWithInstanceOf.js @@ -0,0 +1,18 @@ +//// [typeGuardsWithInstanceOf.ts] +interface I { global: string; } +var result: I; +var result2: I; + +if (!(result instanceof RegExp)) { + result = result2; +} else if (!result.global) { +} + +//// [typeGuardsWithInstanceOf.js] +var result; +var result2; +if (!(result instanceof RegExp)) { + result = result2; +} +else if (!result.global) { +} diff --git a/tests/baselines/reference/typeGuardsWithInstanceOf.types b/tests/baselines/reference/typeGuardsWithInstanceOf.types new file mode 100644 index 0000000000..0d7b477fae --- /dev/null +++ b/tests/baselines/reference/typeGuardsWithInstanceOf.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts === +interface I { global: string; } +>I : I +>global : string + +var result: I; +>result : I +>I : I + +var result2: I; +>result2 : I +>I : I + +if (!(result instanceof RegExp)) { +>!(result instanceof RegExp) : boolean +>(result instanceof RegExp) : boolean +>result instanceof RegExp : boolean +>result : I +>RegExp : RegExpConstructor + + result = result2; +>result = result2 : I +>result : I +>result2 : I + +} else if (!result.global) { +>!result.global : boolean +>result.global : string +>result : I +>global : string +} diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts new file mode 100644 index 0000000000..2750eb96eb --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOf.ts @@ -0,0 +1,8 @@ +interface I { global: string; } +var result: I; +var result2: I; + +if (!(result instanceof RegExp)) { + result = result2; +} else if (!result.global) { +} \ No newline at end of file