diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 936afefce9b..c0a487ffa0f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3055,7 +3055,7 @@ namespace ts { function getRestType(source: Type, properties: PropertyName[], symbol: Symbol): Type { if (source.flags & TypeFlags.Union) { - const types = filter((source).types, t => !(t.flags & TypeFlags.Nullable)); + const types = filterNulableTypes(source); if (types.length) { return getUnionType(map(types, t => getRestType(t, properties, symbol))); } @@ -6103,6 +6103,10 @@ namespace ts { return symbol ? getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) : undefined; } + function filterNulableTypes(union: UnionType): Type[] { + return filter(union.types, t => !(t.flags & TypeFlags.Nullable)); + } + /** * Since the source of spread types are object literals, which are not binary, * this function should be called in a left folding style, with left = previous result of getSpreadType @@ -6114,7 +6118,7 @@ namespace ts { } if (left.flags & TypeFlags.Union) { - const types = filter((left).types, t => !(t.flags & TypeFlags.Nullable)); + const types = filterNulableTypes(left); if (types.length) { return getUnionType(map(types, t => getSpreadType(t, right, isFromObjectLiteral))); } @@ -6127,7 +6131,7 @@ namespace ts { } if (right.flags & TypeFlags.Union) { - const types = filter((right).types, t => !(t.flags & TypeFlags.Nullable)); + const types = filterNulableTypes(right); if (types.length) { return getUnionType(map(types, t => getSpreadType(left, t, isFromObjectLiteral))); }