0

I started learning react with typescript a few days ago and I am getting this error

    /home/sotiris/Github/ecommerce-merng-platform/admin/src/components/DashboardHOC/DashboardHOC.tsx
TypeScript error in /home/sotiris/Github/ecommerce-merng-platform/admin/src/components/DashboardHOC/DashboardHOC.tsx(118,22):
No overload matches this call.
  Overload 1 of 2, '(props: { component: ElementType<any>; } & { children: string | number | boolean | {} | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | ReactNodeArray | ReactPortal; disableGutters?: boolean | undefined; fixed?: boolean | undefined; maxWidth?: false | ... 5 more ... | undefined; } & CommonProps<...> & Pick<...>): Element', gave the following error.
    Type 'ReactNode' is not assignable to type 'string | number | boolean | {} | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | ReactNodeArray | ReactPortal'.
      Type 'undefined' is not assignable to type 'string | number | boolean | {} | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | ReactNodeArray | ReactPortal'.
  Overload 2 of 2, '(props: DefaultComponentProps<ContainerTypeMap<{}, "div">>): Element', gave the following error.
    Type 'ReactNode' is not assignable to type 'string | number | boolean | {} | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | ReactNodeArray | ReactPortal'.
      Type 'undefined' is not assignable to type 'string | number | boolean | {} | ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<...>)> | ReactNodeArray | ReactPortal'.  TS2769

    116 |       <main className={classes.content}>
    117 |         <ErrorAlert>
  > 118 |           <Container>{children}</Container>
        |                      ^
    119 |         </ErrorAlert>
    120 |       </main>
    121 |     </div>

Dashboard.tsx

const DashboardHOC: React.FC<React.ReactNode> = ({ children }) => {
   ...
    {children}
   ...
}

Error.tsx

const Error: React.FC<React.ReactNode> = ({ children }) => {
   ...
    {children}
   ...
}

What Am i doing wrong ?

1 Answer 1

1
React.FC<React.ReactNode>

This means that your props will be a react node, which is never correct. Props are a plain object which you can define any number of properties on. Some of those properties might be react nodes, but the object itself will not.

If you're trying to specify that children is a ReactNode and there are no other props, then React.FC already does that and you can do:

const DashboardHOC: React.FC = ({ children }) => {

Or if you prefer to be explicit that there are no other props:

const DashboardHOC: React.FC<{}> = ({ children }) => {
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.