From afbbcdd490fc803a7ea12c360ae3f2b6a7d41821 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Fri, 30 Jun 2017 10:06:17 -0700 Subject: [PATCH] getSwitchClauseTypes: exit early if getTypeOfSwitchClause is undefined --- src/compiler/checker.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bc2f859f8ecb9..0a8d01dce351f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11067,8 +11067,14 @@ namespace ts { if (!links.switchTypes) { // If all case clauses specify expressions that have unit types, we return an array // of those unit types. Otherwise we return an empty array. - const types = map(switchStatement.caseBlock.clauses, getTypeOfSwitchClause); - links.switchTypes = !contains(types, undefined) ? types : emptyArray; + links.switchTypes = []; + for (const clause of switchStatement.caseBlock.clauses) { + const type = getTypeOfSwitchClause(clause); + if (type === undefined) { + return links.switchTypes = emptyArray; + } + links.switchTypes.push(type); + } } return links.switchTypes; }