Skip to content

Commit

Permalink
Changed logic that computes union types to strip out NoReturn types i…
Browse files Browse the repository at this point in the history
…f they are combined with other types. A "NoReturn" should always appear by itself, never in a union.
  • Loading branch information
msfterictraut committed Jun 18, 2020
1 parent afceb82 commit 88305fc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/src/analyzer/types.ts
Expand Up @@ -1315,6 +1315,13 @@ export function combineTypes(types: Type[]): Type {
return 0;
});

// If the union contains a NoReturn, remove it. NoReturn should
// be used only when it's by itself.
const isNoReturn = (t: Type) => t.category === TypeCategory.Object && ClassType.isBuiltIn(t.classType, 'NoReturn');
if (expandedTypes.find((t) => isNoReturn(t))) {
expandedTypes = expandedTypes.filter((t) => !isNoReturn(t));
}

const resultingTypes = [expandedTypes[0]];
expandedTypes.forEach((t, index) => {
if (index > 0) {
Expand Down

0 comments on commit 88305fc

Please sign in to comment.