Skip to content

Commit 1f19fd6

Browse files
author
Yui T
committed
Don't stop checking other attributes even though we see spread type. This is so that things are correctly marked as reference and type-checked
1 parent 8a30678 commit 1f19fd6

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/compiler/checker.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13211,6 +13211,8 @@ namespace ts {
1321113211
let attributesTable = createMap<Symbol>();
1321213212
let spread: Type = emptyObjectType;
1321313213
let attributesArray: Symbol[] = [];
13214+
let hasSpreadAnyType = false;
13215+
1321413216
for (const attributeDecl of attributes.properties) {
1321513217
const member = attributeDecl.symbol;
1321613218
if (isJsxAttribute(attributeDecl)) {
@@ -13239,31 +13241,33 @@ namespace ts {
1323913241
const exprType = checkExpression(attributeDecl.expression);
1324013242
if (!isValidSpreadType(exprType)) {
1324113243
error(attributeDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
13242-
return anyType;
13244+
hasSpreadAnyType = true;
1324313245
}
1324413246
if (isTypeAny(exprType)) {
13245-
return anyType;
13247+
hasSpreadAnyType = true;
1324613248
}
1324713249
spread = getSpreadType(spread, exprType);
1324813250
}
1324913251
}
1325013252

13251-
if (spread !== emptyObjectType) {
13252-
if (attributesArray.length > 0) {
13253-
spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable));
13254-
attributesArray = [];
13255-
attributesTable = createMap<Symbol>();
13253+
if (!hasSpreadAnyType) {
13254+
if (spread !== emptyObjectType) {
13255+
if (attributesArray.length > 0) {
13256+
spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable));
13257+
attributesArray = [];
13258+
attributesTable = createMap<Symbol>();
13259+
}
13260+
attributesArray = getPropertiesOfType(spread);
1325613261
}
13257-
attributesArray = getPropertiesOfType(spread);
13258-
}
1325913262

13260-
attributesTable = createMap<Symbol>();
13261-
if (attributesArray) {
13262-
forEach(attributesArray, (attr) => {
13263-
if (!filter || filter(attr)) {
13264-
attributesTable.set(attr.name, attr);
13265-
}
13266-
});
13263+
attributesTable = createMap<Symbol>();
13264+
if (attributesArray) {
13265+
forEach(attributesArray, (attr) => {
13266+
if (!filter || filter(attr)) {
13267+
attributesTable.set(attr.name, attr);
13268+
}
13269+
});
13270+
}
1326713271
}
1326813272

1326913273
// Handle children attribute
@@ -13287,7 +13291,7 @@ namespace ts {
1328713291
// Error if there is a attribute named "children" and children element.
1328813292
// This is because children element will overwrite the value from attributes
1328913293
const jsxChildrenPropertyName = getJsxElementChildrenPropertyname();
13290-
if (jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
13294+
if (!hasSpreadAnyType && jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
1329113295
if (attributesTable.has(jsxChildrenPropertyName)) {
1329213296
error(attributes, Diagnostics._0_are_specified_twice_The_attribute_named_0_will_be_overwritten, jsxChildrenPropertyName);
1329313297
}
@@ -13301,7 +13305,7 @@ namespace ts {
1330113305
}
1330213306
}
1330313307

13304-
return createJsxAttributesType(attributes.symbol, attributesTable);
13308+
return hasSpreadAnyType ? anyType : createJsxAttributesType(attributes.symbol, attributesTable);
1330513309

1330613310
/**
1330713311
* Create anonymous type from given attributes symbol table.

0 commit comments

Comments
 (0)