Fix #15463: use intersection types to emulate spread in generic react components (#15851)

* Fix #15463: use intersection types to emulate spread in generic react components

* Fix lint errors

* reverse condition
This commit is contained in:
Mohamed Hegazy
2017-05-15 15:46:50 -07:00
committed by GitHub
parent f93c71c34e
commit d51e467238
11 changed files with 197 additions and 33 deletions

View File

@@ -13314,6 +13314,7 @@ namespace ts {
let spread: Type = emptyObjectType;
let attributesArray: Symbol[] = [];
let hasSpreadAnyType = false;
let typeToIntersect: Type;
let explicitlySpecifyChildrenAttribute = false;
const jsxChildrenPropertyName = getJsxElementChildrenPropertyname();
@@ -13345,11 +13346,16 @@ namespace ts {
attributesArray = [];
attributesTable = createMap<Symbol>();
}
const exprType = getApparentType(checkExpression(attributeDecl.expression));
const exprType = checkExpression(attributeDecl.expression);
if (isTypeAny(exprType)) {
hasSpreadAnyType = true;
}
spread = getSpreadType(spread, exprType);
if (isValidSpreadType(exprType)) {
spread = getSpreadType(spread, exprType);
}
else {
typeToIntersect = typeToIntersect ? getIntersectionType([typeToIntersect, exprType]) : exprType;
}
}
}
@@ -13404,7 +13410,13 @@ namespace ts {
}
}
return hasSpreadAnyType ? anyType : createJsxAttributesType(attributes.symbol, attributesTable);
if (hasSpreadAnyType) {
return anyType;
}
const attributeType = createJsxAttributesType(attributes.symbol, attributesTable);
return typeToIntersect && attributesTable.size ? getIntersectionType([typeToIntersect, attributeType]) :
typeToIntersect ? typeToIntersect : attributeType;
/**
* Create anonymous type from given attributes symbol table.