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

@types/styled-componets not block @types/react version #3721

Closed
xingyibiao opened this issue Apr 8, 2022 · 4 comments
Closed

@types/styled-componets not block @types/react version #3721

xingyibiao opened this issue Apr 8, 2022 · 4 comments

Comments

@xingyibiao
Copy link

Environment

npx envinfo --system --binaries --npmPackages styled-components,babel-plugin-styled-components --markdown --clipboard

System:

  • OS: macOS 12.3.1
  • CPU: (10) x64 Apple M1 Pro
  • Memory: 827.79 MB / 32.00 GB
  • Shell: 5.8 - /bin/zsh

Binaries:

  • Node: 12.14.1 - ~/.nvm/versions/node/v12.14.1/bin/node
  • Yarn: 1.22.17 - ~/.nvm/versions/node/v12.14.1/bin/yarn
  • npm: 6.13.4 - ~/.nvm/versions/node/v12.14.1/bin/npm

npmPackages:

  • styled-components: 5.1.1 => 5.1.1

Reproduction

https://codesandbox.io/s/styled-components-base-gc367

Steps to reproduce

npx react-app-rewired build

tsc throw an error: Type 'ReactElement<any, string | JSXElementConstructor>' is not assignable to type 'ReactNode'

node_modules/@types/styled-components/node_modules/@types/react/package.json version is 18.0.0

@types/styled-components dependencies: "@types/hoist-non-react-statics": "",
"@types/react": "
",

Is @types/react v18 has break change, but @types/styled-components not block that version?

Expected Behavior

build success

Actual Behavior

build error

@xingyibiao
Copy link
Author

my react and react-dom version is 16.9.0, not ready to upgrade react@18

@ethandaniel
Copy link

ethandaniel commented Apr 8, 2022

I'm getting the same error! Seems like styled-components ReactNode overwrites React.ReactNode type. Please help me figure out how to fix this. Error shown below:

No overload matches this call.
Overload 1 of 2, '(props: SwitchProps | Readonly): Switch', gave the following error.
Type 'React.ReactNode' is not assignable to type 'import("node_modules/@types/styled-components/node_modules/@types/react/index").ReactNode'.
Type '{}' is not assignable to type 'ReactNode'.
Overload 2 of 2, '(props: SwitchProps, context: any): Switch', gave the following error.
Type 'React.ReactNode' is not assignable to type 'import("node_modules/@types/styled-components/node_modules/@types/react/index").ReactNode'.ts(2769)
index.d.ts(125, 5): The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly'
index.d.ts(125, 5): The expected type comes from property 'children' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly'
Screen Shot 2022-04-08 at 9 22 13 AM

@stitch-rich
Copy link

This is an issue with @types/styled-components not styled components itself. The type is requiring * of @types/react. The simplest fix if you are not ready to update is to add a manual resolution for now in your package.json to enforce a version below 18 of @types/react

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

@xingyibiao
Copy link
Author

xingyibiao commented Apr 8, 2022

This is an issue with @types/styled-components not styled components itself. The type is requiring * of @types/react. The simplest fix if you are not ready to update is to add a manual resolution for now in your package.json to enforce a version below 18 of @types/react

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

if use npm, maybe should move @types/react to dependencies after set resolutions not fix

set it: issue

thx, fix me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants