Skip to content

Commit 815af7d

Browse files
author
Andy
authored
getSwitchClauseTypes: exit early if getTypeOfSwitchClause is undefined (microsoft#16865)
1 parent 50f3910 commit 815af7d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11066,8 +11066,14 @@ namespace ts {
1106611066
if (!links.switchTypes) {
1106711067
// If all case clauses specify expressions that have unit types, we return an array
1106811068
// of those unit types. Otherwise we return an empty array.
11069-
const types = map(switchStatement.caseBlock.clauses, getTypeOfSwitchClause);
11070-
links.switchTypes = !contains(types, undefined) ? types : emptyArray;
11069+
links.switchTypes = [];
11070+
for (const clause of switchStatement.caseBlock.clauses) {
11071+
const type = getTypeOfSwitchClause(clause);
11072+
if (type === undefined) {
11073+
return links.switchTypes = emptyArray;
11074+
}
11075+
links.switchTypes.push(type);
11076+
}
1107111077
}
1107211078
return links.switchTypes;
1107311079
}

0 commit comments

Comments
 (0)