Skip to content

Commit 331285b

Browse files
Kanchalai Tanglertsampanmhegazy
authored andcommitted
getApparentType for each constituent of props type of the targetAttributesType
1 parent 35001e9 commit 331285b

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
@@ -13467,6 +13467,17 @@ namespace ts {
1346713467
return _jsxElementChildrenPropertyName;
1346813468
}
1346913469

13470+
function createIntersectionOfApparentTypeOfJsxPropsType(propsType: Type): Type {
13471+
if (propsType && propsType.flags & TypeFlags.Intersection) {
13472+
const propsApprentType: Type[] = [];
13473+
for (const t of (<UnionOrIntersectionType>propsType).types) {
13474+
propsApprentType.push(getApparentType(t));
13475+
}
13476+
return getIntersectionType(propsApprentType);
13477+
}
13478+
return propsType;
13479+
}
13480+
1347013481
/**
1347113482
* Get JSX attributes type by trying to resolve openingLikeElement as a stateless function component.
1347213483
* Return only attributes type of successfully resolved call signature.
@@ -13487,6 +13498,7 @@ namespace ts {
1348713498
if (callSignature !== unknownSignature) {
1348813499
const callReturnType = callSignature && getReturnTypeOfSignature(callSignature);
1348913500
let paramType = callReturnType && (callSignature.parameters.length === 0 ? emptyObjectType : getTypeOfSymbol(callSignature.parameters[0]));
13501+
paramType = createIntersectionOfApparentTypeOfJsxPropsType(paramType);
1349013502
if (callReturnType && isTypeAssignableTo(callReturnType, jsxStatelessElementType)) {
1349113503
// Intersect in JSX.IntrinsicAttributes if it exists
1349213504
const intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes);
@@ -13524,7 +13536,8 @@ namespace ts {
1352413536
let allMatchingAttributesType: Type;
1352513537
for (const candidate of candidatesOutArray) {
1352613538
const callReturnType = getReturnTypeOfSignature(candidate);
13527-
const paramType = callReturnType && (candidate.parameters.length === 0 ? emptyObjectType : getTypeOfSymbol(candidate.parameters[0]));
13539+
let paramType = callReturnType && (candidate.parameters.length === 0 ? emptyObjectType : getTypeOfSymbol(candidate.parameters[0]));
13540+
paramType = createIntersectionOfApparentTypeOfJsxPropsType(paramType);
1352813541
if (callReturnType && isTypeAssignableTo(callReturnType, jsxStatelessElementType)) {
1352913542
let shouldBeCandidate = true;
1353013543
for (const attribute of openingLikeElement.attributes.properties) {

0 commit comments

Comments
 (0)