Skip to content

Commit 1125657

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 78df754 commit 1125657

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
@@ -13248,6 +13248,8 @@ namespace ts {
1324813248
let attributesTable = createMap<Symbol>();
1324913249
let spread: Type = emptyObjectType;
1325013250
let attributesArray: Symbol[] = [];
13251+
let hasSpreadAnyType = false;
13252+
1325113253
for (const attributeDecl of attributes.properties) {
1325213254
const member = attributeDecl.symbol;
1325313255
if (isJsxAttribute(attributeDecl)) {
@@ -13276,31 +13278,33 @@ namespace ts {
1327613278
const exprType = checkExpression(attributeDecl.expression);
1327713279
if (!isValidSpreadType(exprType)) {
1327813280
error(attributeDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
13279-
return anyType;
13281+
hasSpreadAnyType = true;
1328013282
}
1328113283
if (isTypeAny(exprType)) {
13282-
return anyType;
13284+
hasSpreadAnyType = true;
1328313285
}
1328413286
spread = getSpreadType(spread, exprType);
1328513287
}
1328613288
}
1328713289

13288-
if (spread !== emptyObjectType) {
13289-
if (attributesArray.length > 0) {
13290-
spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable));
13291-
attributesArray = [];
13292-
attributesTable = createMap<Symbol>();
13290+
if (!hasSpreadAnyType) {
13291+
if (spread !== emptyObjectType) {
13292+
if (attributesArray.length > 0) {
13293+
spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable));
13294+
attributesArray = [];
13295+
attributesTable = createMap<Symbol>();
13296+
}
13297+
attributesArray = getPropertiesOfType(spread);
1329313298
}
13294-
attributesArray = getPropertiesOfType(spread);
13295-
}
1329613299

13297-
attributesTable = createMap<Symbol>();
13298-
if (attributesArray) {
13299-
forEach(attributesArray, (attr) => {
13300-
if (!filter || filter(attr)) {
13301-
attributesTable.set(attr.name, attr);
13302-
}
13303-
});
13300+
attributesTable = createMap<Symbol>();
13301+
if (attributesArray) {
13302+
forEach(attributesArray, (attr) => {
13303+
if (!filter || filter(attr)) {
13304+
attributesTable.set(attr.name, attr);
13305+
}
13306+
});
13307+
}
1330413308
}
1330513309

1330613310
// Handle children attribute
@@ -13324,7 +13328,7 @@ namespace ts {
1332413328
// Error if there is a attribute named "children" and children element.
1332513329
// This is because children element will overwrite the value from attributes
1332613330
const jsxChildrenPropertyName = getJsxElementChildrenPropertyname();
13327-
if (jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
13331+
if (!hasSpreadAnyType && jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
1332813332
if (attributesTable.has(jsxChildrenPropertyName)) {
1332913333
error(attributes, Diagnostics._0_are_specified_twice_The_attribute_named_0_will_be_overwritten, jsxChildrenPropertyName);
1333013334
}
@@ -13338,7 +13342,7 @@ namespace ts {
1333813342
}
1333913343
}
1334013344

13341-
return createJsxAttributesType(attributes.symbol, attributesTable);
13345+
return hasSpreadAnyType ? anyType : createJsxAttributesType(attributes.symbol, attributesTable);
1334213346

1334313347
/**
1334413348
* Create anonymous type from given attributes symbol table.

0 commit comments

Comments
 (0)