react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

"Using a Function As <Admin> Child" gives "not assignable to type 'ReactNode'.ts(2322)" with @types/react 18

Open psam44 opened this issue 2 years ago • 4 comments

A typescript error appears on:

<Admin ...>
  {fetchResources}
</Admin>
Type '(permissions: Permissions) => JSX.Element[]' is not assignable to type 'ReactNode'.ts(2322)
App.tsx(119, 9): Did you mean to call this expression?
const fetchResources: (permissions: Permissions) => JSX.Element[]

This happens with an upgrade to @types/[email protected]

It was fine before, with @types/[email protected]

Workaround:

  • (more to prouve the origin of the problem): Add into node_modules\@types\react\index.d.ts, for type ReactNode =:
        | {}

This option was removed in v18, as stated in Remove {} from ReactFragment

  • Mute the error:
<Admin ...>
  {
    // @ts-expect-error
    fetchResources}
</Admin>

Environment

psam44 avatar Feb 05 '24 16:02 psam44

Thanks for the report. Can you please provide a reproduction sandbox?

slax57 avatar Feb 06 '24 10:02 slax57

I did nothing, just clicked on your link and opened the index.tsx file: image

Noticeable in yarn.lock: "@types/react@*": version "18.2.8"

psam44 avatar Feb 06 '24 16:02 psam44

May be a hint, with what is usually children: AdminChildren, in ra-ui-materialui\src\theme\ThemeProvider.tsx:

export interface ThemeProviderProps {
    children: ReactNode;

and so on, deeper in @mui/material/styles.

psam44 avatar Feb 06 '24 17:02 psam44

Indeed, it can be reproduced straight from the sandbox! :sweat_smile: We'll look into it, thanks!

It's also worth mentioning that this may have been fixed already on the next branch, since we upgraded our monorepo to use React 18 for the upcoming v5.

We need to check whether this fix could be applied to the master branch too, or if it requires a breaking change.

slax57 avatar Feb 06 '24 17:02 slax57

I don't see this issue in v5 so I'm closing this issue. Feel free to reopen if needed

djhi avatar Jul 23 '24 13:07 djhi