Merge pull request #15789 from Microsoft/master-fix15742

[Master] fix15742
This commit is contained in:
Mohamed Hegazy
2017-05-12 12:22:43 -07:00
committed by GitHub
32 changed files with 950 additions and 5 deletions

View File

@@ -13574,6 +13574,20 @@ namespace ts {
return _jsxElementChildrenPropertyName;
}
function getApparentTypeOfJsxPropsType(propsType: Type): Type {
if (!propsType) {
return undefined;
}
if (propsType.flags & TypeFlags.Intersection) {
const propsApparentType: Type[] = [];
for (const t of (<UnionOrIntersectionType>propsType).types) {
propsApparentType.push(getApparentType(t));
}
return getIntersectionType(propsApparentType);
}
return getApparentType(propsType);
}
/**
* Get JSX attributes type by trying to resolve openingLikeElement as a stateless function component.
* Return only attributes type of successfully resolved call signature.
@@ -13594,6 +13608,7 @@ namespace ts {
if (callSignature !== unknownSignature) {
const callReturnType = callSignature && getReturnTypeOfSignature(callSignature);
let paramType = callReturnType && (callSignature.parameters.length === 0 ? emptyObjectType : getTypeOfSymbol(callSignature.parameters[0]));
paramType = getApparentTypeOfJsxPropsType(paramType);
if (callReturnType && isTypeAssignableTo(callReturnType, jsxStatelessElementType)) {
// Intersect in JSX.IntrinsicAttributes if it exists
const intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes);
@@ -13631,7 +13646,8 @@ namespace ts {
let allMatchingAttributesType: Type;
for (const candidate of candidatesOutArray) {
const callReturnType = getReturnTypeOfSignature(candidate);
const paramType = callReturnType && (candidate.parameters.length === 0 ? emptyObjectType : getTypeOfSymbol(candidate.parameters[0]));
let paramType = callReturnType && (candidate.parameters.length === 0 ? emptyObjectType : getTypeOfSymbol(candidate.parameters[0]));
paramType = getApparentTypeOfJsxPropsType(paramType);
if (callReturnType && isTypeAssignableTo(callReturnType, jsxStatelessElementType)) {
let shouldBeCandidate = true;
for (const attribute of openingLikeElement.attributes.properties) {