* 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 * and right = the new element to be spread.
(left, right, symbol, objectFlags, readonly)
| 62905 | * and right = the new element to be spread. |
| 62906 | */ |
| 62907 | function getSpreadType(left, right, symbol, objectFlags, readonly) { |
| 62908 | if (left.flags & 1 /* TypeFlags.Any */ || right.flags & 1 /* TypeFlags.Any */) { |
| 62909 | return anyType; |
| 62910 | } |
| 62911 | if (left.flags & 2 /* TypeFlags.Unknown */ || right.flags & 2 /* TypeFlags.Unknown */) { |
| 62912 | return unknownType; |
| 62913 | } |
| 62914 | if (left.flags & 131072 /* TypeFlags.Never */) { |
| 62915 | return right; |
| 62916 | } |
| 62917 | if (right.flags & 131072 /* TypeFlags.Never */) { |
| 62918 | return left; |
| 62919 | } |
| 62920 | left = tryMergeUnionOfObjectTypeAndEmptyObject(left, readonly); |
| 62921 | if (left.flags & 1048576 /* TypeFlags.Union */) { |
| 62922 | return checkCrossProductUnion([left, right]) |
| 62923 | ? mapType(left, function (t) { return getSpreadType(t, right, symbol, objectFlags, readonly); }) |
| 62924 | : errorType; |
| 62925 | } |
| 62926 | right = tryMergeUnionOfObjectTypeAndEmptyObject(right, readonly); |
| 62927 | if (right.flags & 1048576 /* TypeFlags.Union */) { |
| 62928 | return checkCrossProductUnion([left, right]) |
| 62929 | ? mapType(right, function (t) { return getSpreadType(left, t, symbol, objectFlags, readonly); }) |
| 62930 | : errorType; |
| 62931 | } |
| 62932 | if (right.flags & (528 /* TypeFlags.BooleanLike */ | 296 /* TypeFlags.NumberLike */ | 2112 /* TypeFlags.BigIntLike */ | 402653316 /* TypeFlags.StringLike */ | 1056 /* TypeFlags.EnumLike */ | 67108864 /* TypeFlags.NonPrimitive */ | 4194304 /* TypeFlags.Index */)) { |
| 62933 | return left; |
| 62934 | } |
| 62935 | if (isGenericObjectType(left) || isGenericObjectType(right)) { |
| 62936 | if (isEmptyObjectType(left)) { |
| 62937 | return right; |
| 62938 | } |
| 62939 | // When the left type is an intersection, we may need to merge the last constituent of the |
| 62940 | // intersection with the right type. For example when the left type is 'T & { a: string }' |
| 62941 | // and the right type is '{ b: string }' we produce 'T & { a: string, b: string }'. |
| 62942 | if (left.flags & 2097152 /* TypeFlags.Intersection */) { |
| 62943 | var types = left.types; |
| 62944 | var lastLeft = types[types.length - 1]; |
| 62945 | if (isNonGenericObjectType(lastLeft) && isNonGenericObjectType(right)) { |
| 62946 | return getIntersectionType(ts.concatenate(types.slice(0, types.length - 1), [getSpreadType(lastLeft, right, symbol, objectFlags, readonly)])); |
| 62947 | } |
| 62948 | } |
| 62949 | return getIntersectionType([left, right]); |
| 62950 | } |
| 62951 | var members = ts.createSymbolTable(); |
| 62952 | var skippedPrivateMembers = new ts.Set(); |
| 62953 | var indexInfos = left === emptyObjectType ? getIndexInfosOfType(right) : getUnionIndexInfos([left, right]); |
| 62954 | for (var _i = 0, _a = getPropertiesOfType(right); _i < _a.length; _i++) { |
| 62955 | var rightProp = _a[_i]; |
| 62956 | if (ts.getDeclarationModifierFlagsFromSymbol(rightProp) & (8 /* ModifierFlags.Private */ | 16 /* ModifierFlags.Protected */)) { |
| 62957 | skippedPrivateMembers.add(rightProp.escapedName); |
| 62958 | } |
| 62959 | else if (isSpreadableProperty(rightProp)) { |
| 62960 | members.set(rightProp.escapedName, getSpreadSymbol(rightProp, readonly)); |
| 62961 | } |
| 62962 | } |
| 62963 | for (var _b = 0, _c = getPropertiesOfType(left); _b < _c.length; _b++) { |
| 62964 | var leftProp = _c[_b]; |
no test coverage detected
searching dependent graphs…