Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React 18 implicit children typing issue? #1245

Closed
girvo opened this issue Apr 14, 2022 · 9 comments
Closed

React 18 implicit children typing issue? #1245

girvo opened this issue Apr 14, 2022 · 9 comments
Labels
help wanted Contributions from community are welcome

Comments

@girvo
Copy link

girvo commented Apr 14, 2022

What package has an issue

@mantine/core

Describe the bug

So the @types/react typing package for TypeScript, for React 18, has remove the implicit children for all component types, and this is causing me to run into some issues with our extensions of some Mantine components.

import React, { ComponentType, Key, Fragment } from 'react'

// given a Props interface with this:
  header?: () => React.ReactNode
}

// snip
  return (
    <div className={classes.grid}>
      {props.header && (
        <MediaQuery largerThan="sm" styles={hide}>
          {props.header()}
        </MediaQuery>
      )}

When used with React 18.0.1, @types/react 18.0.1 and @mantine/core v4.1.3, this gives an error about React.ReactNode not being React.ReactNode!

At the {props.header()} line:

Type 'React.ReactNode' is not assignable to type 'import("/workspaces/cobalt-dev/node_modules/@types/react/index").ReactNode'.
  Type '{}' is not assignable to type 'ReactNode'.

I'm not entirely sure what is causing this, other than some kind of typing mismatch when trying to use React v18 and it's v18 @types package with Mantine?

In which browser did the problem occur

All browsers

If possible, please include a link to a codesandbox with the reproduced problem

No response

Do you know how to fix the issue

No response

Are you willing to participate in fixing this issue and create a pull request with the fix

No response

Possible fix

No response

@girvo girvo added the bug label Apr 14, 2022
@fl0wx
Copy link

fl0wx commented Apr 14, 2022

@rtivital
Copy link
Member

Mantine does not use FC type anywhere, so most likely provided codemod will not help.

@rtivital rtivital added help wanted Contributions from community are welcome react-18 and removed bug labels Apr 15, 2022
@girvo
Copy link
Author

girvo commented Apr 19, 2022

@rtivital Yeah I initially assumed it was something to do with that as well initially (you can tell in my initial paragraph thats what I thought it was) but then checked the source and saw that the FC type isn't used anywhere, and yet the type error still exists. Super odd.

Is there anything I can do to help with tracking this down? It's unfortunately prevented us from migrating to v18 at work. Happy to do some more debugging or see if I can reproduce a tiny test case for it if need be, or post more of the source we have for it, but it's super weird. Basically thinks it's React.ReactNode type is the empty object, instead of the actual ReactNode definition, despite both my code and Mantine ostensibly using the same @types/react package

https://stackoverflow.com/questions/71852153/type-is-not-assignable-to-type-reactnode

facebook/react#24304

In a different context, someone else has run into this recently as well, but without much success in tracking down the issue it seems

@wes337
Copy link
Contributor

wes337 commented Apr 19, 2022

Mantine does not use FC type anywhere, so most likely provided codemod will not help.

Are you sure? I ran the codemod (https://github.com/eps1lon/types-react-codemod) and quite a few changes were made:

image

@wes337
Copy link
Contributor

wes337 commented Apr 20, 2022

@girvo Have you tried adding React 17 to the resolutions of your package.json?

"resolutions": {
    "@types/react": "17.0.8"
}

@girvo
Copy link
Author

girvo commented Apr 22, 2022

@wes337 While using [email protected] as-the-library itself?

@wes337
Copy link
Contributor

wes337 commented Apr 22, 2022

I think so. I was just reading in that issue you linked, and many people found a solution using resolutions: facebook/react#24304 (comment).

@spigelli
Copy link

spigelli commented Jun 29, 2022

Also experiencing

TS2322: Type '{ children: Element[]; size: "sm"; style: { height: string; }; }' is not assignable to type 'IntrinsicAttributes & ContainerProps & RefAttributes'.   Property 'children' does not exist on type 'IntrinsicAttributes & ContainerProps & RefAttributes'.

With versions:

    "@types/react": "18.0.13",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "@mantine/core": "^4.2.11",

Not sure if that's related

@rtivital
Copy link
Member

Fixed in 5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions from community are welcome
Projects
None yet
Development

No branches or pull requests

5 participants