Skip to content

Conversation

weswigham
Copy link
Member

Fixes #27948 in the general case where the union elements are like ComponentType - very similar signatures in each union member.

function checkJsxReturnAssignableToAppropriateBound(isSFC: boolean, elemInstanceType: Type, openingLikeElement: Node) {
if (isSFC) {
function checkJsxReturnAssignableToAppropriateBound(refKind: JsxReferenceKind, elemInstanceType: Type, openingLikeElement: Node) {
if (refKind === JsxReferenceKind.Function) {
const sfcReturnConstraint = getJsxStatelessElementTypeAt(openingLikeElement);
if (sfcReturnConstraint) {
checkTypeRelatedTo(elemInstanceType, sfcReturnConstraint, assignableRelation, openingLikeElement, Diagnostics.JSX_element_type_0_is_not_a_constructor_function_for_JSX_elements);
Copy link

@Jessidhia Jessidhia Oct 26, 2018

Choose a reason for hiding this comment

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

(note) as of React 16, components are also allowed to return number / string / boolean (in other words, anything other than undefined, symbol or a non-Element, non-Array object), but at least TS@latest will reject SFC which include those return types. It does validate with classes, just not functions.

If fixed this probably goes in another PR though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants