Skip to content

Union of React function components is not callable #28575

@karol-majewski

Description

@karol-majewski

TypeScript Version: @3.2.0-dev.20181116

Search Terms: jsx invocations function calls resolution

Code

import * as React from 'react';

declare const Radio: () => React.ReactElement<{}>;
declare const Checkbox: React.FC;

declare const condition1: boolean;
declare const condition2: boolean;
declare const condition3: boolean;

const RandomComponent: React.FC = () => {
  if (condition1) {
    return <Radio />; // No problem
  }

  if (condition2) {
    return <Checkbox />; // No problem
  }

  const Component =
    condition3
      ? Radio
      : Checkbox;

  return <Component />; // Error: JSX element type 'Component' does not have any construct or call signatures.
};

Expected behavior:

Compiles without error.

Actual behavior:

Error: JSX element type 'Component' does not have any construct or call signatures. is reported next to return <Component />. While any of them is callable, the union of them is not.

Playground Link:

Related Issues:

Changes to JSX resolution were described in https://blogs.msdn.microsoft.com/typescript/2018/11/15/announcing-typescript-3-2-rc/.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JSX/TSXRelates to the JSX parser and emitter

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions