Skip to content

Commit 2178d55

Browse files
committed
extract filterNullableTypes
1 parent 51f5ef6 commit 2178d55

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,7 +3055,7 @@ namespace ts {
30553055

30563056
function getRestType(source: Type, properties: PropertyName[], symbol: Symbol): Type {
30573057
if (source.flags & TypeFlags.Union) {
3058-
const types = filter((<UnionType>source).types, t => !(t.flags & TypeFlags.Nullable));
3058+
const types = filterNulableTypes(<UnionType>source);
30593059
if (types.length) {
30603060
return getUnionType(map(types, t => getRestType(t, properties, symbol)));
30613061
}
@@ -6103,6 +6103,10 @@ namespace ts {
61036103
return symbol ? getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol) : undefined;
61046104
}
61056105

6106+
function filterNulableTypes(union: UnionType): Type[] {
6107+
return filter(union.types, t => !(t.flags & TypeFlags.Nullable));
6108+
}
6109+
61066110
/**
61076111
* Since the source of spread types are object literals, which are not binary,
61086112
* this function should be called in a left folding style, with left = previous result of getSpreadType
@@ -6114,7 +6118,7 @@ namespace ts {
61146118
}
61156119

61166120
if (left.flags & TypeFlags.Union) {
6117-
const types = filter((<UnionType>left).types, t => !(t.flags & TypeFlags.Nullable));
6121+
const types = filterNulableTypes(<UnionType>left);
61186122
if (types.length) {
61196123
return getUnionType(map(types, t => getSpreadType(t, right, isFromObjectLiteral)));
61206124
}
@@ -6127,7 +6131,7 @@ namespace ts {
61276131
}
61286132

61296133
if (right.flags & TypeFlags.Union) {
6130-
const types = filter((<UnionType>right).types, t => !(t.flags & TypeFlags.Nullable));
6134+
const types = filterNulableTypes(<UnionType>right);
61316135
if (types.length) {
61326136
return getUnionType(map(types, t => getSpreadType(left, t, isFromObjectLiteral)));
61336137
}

0 commit comments

Comments
 (0)