8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Typescript & React で Type 'Element' is not assignable to type 'FunctionComponent<Props>'. のエラーがでた

Last updated at Posted at 2019-02-14

状況

Typescript で React を書いていたらこんなエラーがでた。

Type 'Element' is not assignable to type 'FunctionComponent<Props>'.
  Type 'Element' provides no match for the signature '(props: Props & { children?: ReactNode; }, context?: any): ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<...>)>'.ts(2322)

エラーのでた部分はここ。

function MyComponent({ user }): React.FC<Props> {
  return (
    <div>{user.name}</div>
  );
}

解決

function 式で書かずに arrow function で書きなおしたらエラーは消えた。

const MyComponent: React.FC<Props> = ({ user }) => {
  return <div>{user.name}</div>;
};

あとがき

なんでなのかは分からない。

8
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?