Skip to content

Commit 181ff86

Browse files
author
Kanchalai Tanglertsampan
committed
getApparentType for each constituent of props type of the targetAttributesType
1 parent 60def44 commit 181ff86

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/compiler/checker.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13548,6 +13548,17 @@ namespace ts {
1354813548
return _jsxElementChildrenPropertyName;
1354913549
}
1355013550

13551+
function createIntersectionOfApparentTypeOfJsxPropsType(propsType: Type): Type {
13552+
if (propsType && propsType.flags & TypeFlags.Intersection) {
13553+
const propsApprentType: Type[] = [];
13554+
for (const t of (<UnionOrIntersectionType>propsType).types) {
13555+
propsApprentType.push(getApparentType(t));
13556+
}
13557+
return getIntersectionType(propsApprentType);
13558+
}
13559+
return propsType;
13560+
}
13561+
1355113562
/**
1355213563
* Get JSX attributes type by trying to resolve openingLikeElement as a stateless function component.
1355313564
* Return only attributes type of successfully resolved call signature.
@@ -13568,6 +13579,7 @@ namespace ts {
1356813579
if (callSignature !== unknownSignature) {
1356913580
const callReturnType = callSignature && getReturnTypeOfSignature(callSignature);
1357013581
let paramType = callReturnType && (callSignature.parameters.length === 0 ? emptyObjectType : getTypeOfSymbol(callSignature.parameters[0]));
13582+
paramType = createIntersectionOfApparentTypeOfJsxPropsType(paramType);
1357113583
if (callReturnType && isTypeAssignableTo(callReturnType, jsxStatelessElementType)) {
1357213584
// Intersect in JSX.IntrinsicAttributes if it exists
1357313585
const intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes);
@@ -13605,7 +13617,8 @@ namespace ts {
1360513617
let allMatchingAttributesType: Type;
1360613618
for (const candidate of candidatesOutArray) {
1360713619
const callReturnType = getReturnTypeOfSignature(candidate);
13608-
const paramType = callReturnType && (candidate.parameters.length === 0 ? emptyObjectType : getTypeOfSymbol(candidate.parameters[0]));
13620+
let paramType = callReturnType && (candidate.parameters.length === 0 ? emptyObjectType : getTypeOfSymbol(candidate.parameters[0]));
13621+
paramType = createIntersectionOfApparentTypeOfJsxPropsType(paramType);
1360913622
if (callReturnType && isTypeAssignableTo(callReturnType, jsxStatelessElementType)) {
1361013623
let shouldBeCandidate = true;
1361113624
for (const attribute of openingLikeElement.attributes.properties) {

0 commit comments

Comments
 (0)