Skip to content
Prev Previous commit
Next Next commit
Resolve string type to anytype and look up property in intrinsicEleme…
…ntsType of Jsx
  • Loading branch information
Kanchalai Tanglertsampan committed Jun 23, 2016
commit 1369108257137e4ef6274805edf4b00017c7f2d5
23 changes: 23 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9825,6 +9825,29 @@ namespace ts {
}));
}

// If the elemType is a string type, we have to return anyType to prevent an error downstream as we will try to find construct or call signature of the type
if (elemType.flags & TypeFlags.String) {
return anyType;
}
else if (elemType.flags & TypeFlags.StringLiteral) {
// If the elemType is a stringLiteral type, we can then provide a check and give
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finish sentence in comment

const intrinsicElementsType = getJsxType(JsxNames.IntrinsicElements);
if (intrinsicElementsType !== unknownType) {
const stringLiteralTypeName = (<StringLiteralType>elemType).text;
const intrinsicProp = getPropertyOfType(intrinsicElementsType, stringLiteralTypeName);
if (intrinsicProp) {
return getTypeOfSymbol(intrinsicProp);
}
const indexSignatureType = getIndexTypeOfType(intrinsicElementsType, IndexKind.String);
if (indexSignatureType) {
return indexSignatureType;
}
error(node, Diagnostics.Property_0_does_not_exist_on_type_1, stringLiteralTypeName, "JSX." + JsxNames.IntrinsicElements)
// If we need to report an error, we already done so here. So just return any to prevent any more error downstream
return anyType;
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like you return anyType/unknownType if you couldn't find an intrinsicElementsType for a string literal.

Why not make it

if (intrinsicElementsType === unknownType) {
    return unknownType;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is actually intended that if intrinsicElementsType === unknownType then you just fall through and check for the construct/call though, arguably we should actually return unknownType instead


// Get the element instance type (the result of newing or invoking this tag)
const elemInstanceType = getJsxElementInstanceType(node, elemType);

Expand Down