From 181ff8615064edeb5fdf33121973c1d0ec07dc50 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 11 May 2017 16:30:43 -0700 Subject: [PATCH] getApparentType for each constituent of props type of the targetAttributesType --- src/compiler/checker.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 861279b2225..ce89fb72b52 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13548,6 +13548,17 @@ namespace ts { return _jsxElementChildrenPropertyName; } + function createIntersectionOfApparentTypeOfJsxPropsType(propsType: Type): Type { + if (propsType && propsType.flags & TypeFlags.Intersection) { + const propsApprentType: Type[] = []; + for (const t of (propsType).types) { + propsApprentType.push(getApparentType(t)); + } + return getIntersectionType(propsApprentType); + } + return propsType; + } + /** * Get JSX attributes type by trying to resolve openingLikeElement as a stateless function component. * Return only attributes type of successfully resolved call signature. @@ -13568,6 +13579,7 @@ namespace ts { if (callSignature !== unknownSignature) { const callReturnType = callSignature && getReturnTypeOfSignature(callSignature); let paramType = callReturnType && (callSignature.parameters.length === 0 ? emptyObjectType : getTypeOfSymbol(callSignature.parameters[0])); + paramType = createIntersectionOfApparentTypeOfJsxPropsType(paramType); if (callReturnType && isTypeAssignableTo(callReturnType, jsxStatelessElementType)) { // Intersect in JSX.IntrinsicAttributes if it exists const intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes); @@ -13605,7 +13617,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 = createIntersectionOfApparentTypeOfJsxPropsType(paramType); if (callReturnType && isTypeAssignableTo(callReturnType, jsxStatelessElementType)) { let shouldBeCandidate = true; for (const attribute of openingLikeElement.attributes.properties) {