Skip to content

Commit 5e3fefd

Browse files
author
Yui T
committed
Wip-fixing spread type
1 parent 03da13c commit 5e3fefd

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13212,6 +13212,8 @@ namespace ts {
1321213212
let spread: Type = emptyObjectType;
1321313213
let attributesArray: Symbol[] = [];
1321413214
let hasSpreadAnyType = false;
13215+
let explicitlySpecifyChildrenAttribute = false;
13216+
const jsxChildrenPropertyName = getJsxElementChildrenPropertyname();
1321513217

1321613218
for (const attributeDecl of attributes.properties) {
1321713219
const member = attributeDecl.symbol;
@@ -13230,6 +13232,9 @@ namespace ts {
1323013232
attributeSymbol.target = member;
1323113233
attributesTable.set(attributeSymbol.name, attributeSymbol);
1323213234
attributesArray.push(attributeSymbol);
13235+
if (attributeDecl.name.text === jsxChildrenPropertyName) {
13236+
explicitlySpecifyChildrenAttribute = true;
13237+
}
1323313238
}
1323413239
else {
1323513240
Debug.assert(attributeDecl.kind === SyntaxKind.JsxSpreadAttribute);
@@ -13290,8 +13295,7 @@ namespace ts {
1329013295

1329113296
// Error if there is a attribute named "children" and children element.
1329213297
// This is because children element will overwrite the value from attributes
13293-
const jsxChildrenPropertyName = getJsxElementChildrenPropertyname();
13294-
if (!hasSpreadAnyType && jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
13298+
if (explicitlySpecifyChildrenAttribute) {
1329513299
if (attributesTable.has(jsxChildrenPropertyName)) {
1329613300
error(attributes, Diagnostics._0_are_specified_twice_The_attribute_named_0_will_be_overwritten, jsxChildrenPropertyName);
1329713301
}
@@ -13314,7 +13318,7 @@ namespace ts {
1331413318
*/
1331513319
function createJsxAttributesType(symbol: Symbol, attributesTable: Map<Symbol>) {
1331613320
const result = createAnonymousType(symbol, attributesTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined);
13317-
const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral;
13321+
const freshObjectLiteralFlag = spread !== emptyObjectType || compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral;
1331813322
result.flags |= TypeFlags.JsxAttributes | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag;
1331913323
result.objectFlags |= ObjectFlags.ObjectLiteral;
1332013324
return result;
@@ -13866,7 +13870,15 @@ namespace ts {
1386613870
error(openingLikeElement, Diagnostics.JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property, getJsxElementPropertiesName());
1386713871
}
1386813872
else {
13869-
checkTypeAssignableTo(sourceAttributesType, targetAttributesType, openingLikeElement.attributes.properties.length > 0 ? openingLikeElement.attributes : openingLikeElement);
13873+
const isAssignableToTargetAttributes = checkTypeAssignableTo(sourceAttributesType, targetAttributesType, openingLikeElement.attributes.properties.length > 0 ? openingLikeElement.attributes : openingLikeElement);
13874+
// TODO (yuisu): comment
13875+
if (isAssignableToTargetAttributes && sourceAttributesType !== anyType && !(sourceAttributesType.flags & TypeFlags.FreshLiteral)) {
13876+
for (const attribute of openingLikeElement.attributes.properties) {
13877+
if (isJsxAttribute(attribute) && !getPropertyOfType(targetAttributesType, attribute.name.text)) {
13878+
error(attribute, Diagnostics.Property_0_does_not_exist_on_type_1, attribute.name.text, typeToString(targetAttributesType));
13879+
}
13880+
}
13881+
}
1387013882
}
1387113883
}
1387213884

0 commit comments

Comments
 (0)