From f81925992c09ceb6922f2c00e7effd6418981429 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 11 Jun 2017 14:54:36 -0700 Subject: [PATCH] Intersection with 'never' type always produces 'never' --- src/compiler/checker.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bbd38ddbc5d..f5aa57777da 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7168,6 +7168,7 @@ namespace ts { containsAny?: boolean; containsUndefined?: boolean; containsNull?: boolean; + containsNever?: boolean; containsNonWideningType?: boolean; containsString?: boolean; containsNumber?: boolean; @@ -7369,10 +7370,13 @@ namespace ts { else if (type.flags & TypeFlags.Any) { typeSet.containsAny = true; } + else if (type.flags & TypeFlags.Never) { + typeSet.containsNever = true; + } else if (getObjectFlags(type) & ObjectFlags.Anonymous && isEmptyObjectType(type)) { typeSet.containsEmptyObject = true; } - else if (!(type.flags & TypeFlags.Never) && (strictNullChecks || !(type.flags & TypeFlags.Nullable)) && !contains(typeSet, type)) { + else if ((strictNullChecks || !(type.flags & TypeFlags.Nullable)) && !contains(typeSet, type)) { if (type.flags & TypeFlags.Object) { typeSet.containsObjectType = true; } @@ -7410,6 +7414,9 @@ namespace ts { } const typeSet = [] as TypeSet; addTypesToIntersection(typeSet, types); + if (typeSet.containsNever) { + return neverType; + } if (typeSet.containsAny) { return anyType; }