Skip to content

Commit bb23bb2

Browse files
committed
Propagate both TypeFlags and ObjectFlags in getSpreadType
1 parent abc8110 commit bb23bb2

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

src/compiler/checker.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8442,7 +8442,7 @@ namespace ts {
84428442
function getExtendsType(checkType: Type, extendsType: Type): Type {
84438443
// sys.write(`getExtendsType(${typeToString(checkType)}, ${typeToString(extendsType)})\n`);
84448444
if (checkType.flags & TypeFlags.Union) {
8445-
return getUnionType(map((<UnionType>checkType).types, t => getExtendsType(t, extendsType)), /*subtypeReduction*/ false);
8445+
return getUnionType(map((<UnionType>checkType).types, t => getExtendsType(t, extendsType)));
84468446
}
84478447
if (checkType.flags & TypeFlags.Any) {
84488448
return booleanType;
@@ -8501,7 +8501,7 @@ namespace ts {
85018501
* this function should be called in a left folding style, with left = previous result of getSpreadType
85028502
* and right = the new element to be spread.
85038503
*/
8504-
function getSpreadType(left: Type, right: Type, symbol: Symbol, propagatedFlags: TypeFlags): Type {
8504+
function getSpreadType(left: Type, right: Type, symbol: Symbol, typeFlags: TypeFlags, objectFlags: ObjectFlags): Type {
85058505
if (left.flags & TypeFlags.Any || right.flags & TypeFlags.Any) {
85068506
return anyType;
85078507
}
@@ -8512,10 +8512,10 @@ namespace ts {
85128512
return left;
85138513
}
85148514
if (left.flags & TypeFlags.Union) {
8515-
return mapType(left, t => getSpreadType(t, right, symbol, propagatedFlags));
8515+
return mapType(left, t => getSpreadType(t, right, symbol, typeFlags, objectFlags));
85168516
}
85178517
if (right.flags & TypeFlags.Union) {
8518-
return mapType(right, t => getSpreadType(left, t, symbol, propagatedFlags));
8518+
return mapType(right, t => getSpreadType(left, t, symbol, typeFlags, objectFlags));
85198519
}
85208520
if (right.flags & (TypeFlags.BooleanLike | TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.EnumLike | TypeFlags.NonPrimitive)) {
85218521
return left;
@@ -8578,8 +8578,8 @@ namespace ts {
85788578
emptyArray,
85798579
getNonReadonlyIndexSignature(stringIndexInfo),
85808580
getNonReadonlyIndexSignature(numberIndexInfo));
8581-
spread.flags |= propagatedFlags | TypeFlags.ContainsObjectLiteral;
8582-
(spread as ObjectType).objectFlags |= (ObjectFlags.ObjectLiteral | ObjectFlags.ContainsSpread);
8581+
spread.flags |= typeFlags | TypeFlags.ContainsObjectLiteral;
8582+
(spread as ObjectType).objectFlags |= objectFlags | (ObjectFlags.ObjectLiteral | ObjectFlags.ContainsSpread);
85838583
return spread;
85848584
}
85858585

@@ -9552,7 +9552,7 @@ namespace ts {
95529552
}
95539553

95549554
function isIgnoredJsxProperty(source: Type, sourceProp: Symbol, targetMemberType: Type | undefined) {
9555-
return source.flags & TypeFlags.JsxAttributes && !(isUnhyphenatedJsxName(sourceProp.escapedName) || targetMemberType);
9555+
return getObjectFlags(source) & ObjectFlags.JsxAttributes && !(isUnhyphenatedJsxName(sourceProp.escapedName) || targetMemberType);
95569556
}
95579557

95589558
/**
@@ -14905,7 +14905,7 @@ namespace ts {
1490514905
checkExternalEmitHelpers(memberDecl, ExternalEmitHelpers.Assign);
1490614906
}
1490714907
if (propertiesArray.length > 0) {
14908-
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags);
14908+
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags, 0);
1490914909
propertiesArray = [];
1491014910
propertiesTable = createSymbolTable();
1491114911
hasComputedStringProperty = false;
@@ -14917,7 +14917,7 @@ namespace ts {
1491714917
error(memberDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
1491814918
return unknownType;
1491914919
}
14920-
spread = getSpreadType(spread, type, node.symbol, propagatedFlags);
14920+
spread = getSpreadType(spread, type, node.symbol, propagatedFlags, 0);
1492114921
offset = i + 1;
1492214922
continue;
1492314923
}
@@ -14962,7 +14962,7 @@ namespace ts {
1496214962

1496314963
if (spread !== emptyObjectType) {
1496414964
if (propertiesArray.length > 0) {
14965-
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags);
14965+
spread = getSpreadType(spread, createObjectLiteralType(), node.symbol, propagatedFlags, 0);
1496614966
}
1496714967
return spread;
1496814968
}
@@ -15095,15 +15095,15 @@ namespace ts {
1509515095
else {
1509615096
Debug.assert(attributeDecl.kind === SyntaxKind.JsxSpreadAttribute);
1509715097
if (attributesTable.size > 0) {
15098-
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, TypeFlags.JsxAttributes);
15098+
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, 0, ObjectFlags.JsxAttributes);
1509915099
attributesTable = createSymbolTable();
1510015100
}
1510115101
const exprType = checkExpressionCached(attributeDecl.expression, checkMode);
1510215102
if (isTypeAny(exprType)) {
1510315103
hasSpreadAnyType = true;
1510415104
}
1510515105
if (isValidSpreadType(exprType)) {
15106-
spread = getSpreadType(spread, exprType, openingLikeElement.symbol, TypeFlags.JsxAttributes);
15106+
spread = getSpreadType(spread, exprType, openingLikeElement.symbol, 0, ObjectFlags.JsxAttributes);
1510715107
}
1510815108
else {
1510915109
typeToIntersect = typeToIntersect ? getIntersectionType([typeToIntersect, exprType]) : exprType;
@@ -15113,7 +15113,7 @@ namespace ts {
1511315113

1511415114
if (!hasSpreadAnyType) {
1511515115
if (attributesTable.size > 0) {
15116-
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, TypeFlags.JsxAttributes);
15116+
spread = getSpreadType(spread, createJsxAttributesType(), attributes.symbol, 0, ObjectFlags.JsxAttributes);
1511715117
}
1511815118
}
1511915119

@@ -15138,7 +15138,8 @@ namespace ts {
1513815138
createArrayType(getUnionType(childrenTypes));
1513915139
const childPropMap = createSymbolTable();
1514015140
childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol);
15141-
spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined), attributes.symbol, TypeFlags.JsxAttributes);
15141+
spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined),
15142+
attributes.symbol, 0, ObjectFlags.JsxAttributes);
1514215143

1514315144
}
1514415145
}

0 commit comments

Comments
 (0)