From 815af7da175429166fff3ddfe54ccad74c6550b7 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 12 Jul 2017 07:45:02 -0700 Subject: [PATCH] getSwitchClauseTypes: exit early if getTypeOfSwitchClause is undefined (#16865) --- 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 8bab67f7a38..e454b43d4a1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11066,8 +11066,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; }