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

Nesting styled components with styled() and adding prop types does not work correctly #4174

Closed
fabb opened this issue Sep 22, 2023 · 13 comments

Comments

@fabb
Copy link

fabb commented Sep 22, 2023

Environment

System:

  • OS: macOS 13.5.2
  • CPU: (10) arm64 Apple M1 Max
  • Memory: 49.19 MB / 64.00 GB
  • Shell: 5.9 - /bin/zsh

Binaries:

  • Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node
  • Yarn: 1.22.19 - ~/.yarn/bin/yarn
  • npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm

npmPackages:

  • babel-plugin-styled-components: 2.1.4 => 2.1.4
  • styled-components: 6.0.8 => 6.0.8

Reproduction

https://codesandbox.io/s/styled-components-base-forked-j8f2nt?file=/index.tsx

Steps to reproduce

const Component1 = styled.a<{ prop1?: boolean }>``

const Component2 = styled(Component1)<{ prop2?: boolean }>``

const Component3 = styled(Component2)<{ prop3?: boolean }>``

const Component4 = () => <Component3 prop1={true} prop2={true} /> // compiles fine

const Component5 = () => <Component3 prop1={true} prop2={true} prop3={true} /> // compile error, prop2 does not exist

Expected Behavior

Should compile.

Actual Behavior

Component5 does not compile, prop2 cannot be found.

@fabb
Copy link
Author

fabb commented Sep 22, 2023

Maybe the same underlying issue:

const createComponent = (Component: FunctionComponent<{ prop1?: string }>) => styled(Component)<{ prop2?: string }>``

type ComponentProps = React.ComponentProps<ReturnType<typeof createComponent>>

type Prop1 = ComponentProps['prop1'] // compiles fine
type Prop2 = ComponentProps['prop2'] // compile error, prop2 does not exist

@krudos
Copy link
Contributor

krudos commented Sep 26, 2023

i am getting same error with 6.0.8 . with 6.0.7 types are working

@seanmcquaid
Copy link

Seeing the same as well!

@krudos
Copy link
Contributor

krudos commented Sep 28, 2023

i think this is related to
#4165

@ViniDevBR
Copy link

6.0.8 is broken with types... USE 6.0.7

@krudos
Copy link
Contributor

krudos commented Oct 11, 2023

i think this got broken on this commit
6ee6c23

@krudos
Copy link
Contributor

krudos commented Oct 11, 2023

i created this PR
#4190

@krudos
Copy link
Contributor

krudos commented Oct 14, 2023

try 6.1.0

@fabb
Copy link
Author

fabb commented Oct 15, 2023

Same issue in 6.1.0: https://codesandbox.io/s/styled-components-base-forked-j8f2nt?file=/index.tsx

@MarineP31
Copy link

I still got the same issue in 6.1.0 too

@macko911
Copy link

I've added failing tests to help fix this in #4219

@macko911
Copy link

macko911 commented Jan 4, 2024

@fabb my issues have been fixed with the latest version 6.1.6, can you please check on your end and perhaps close this issue? 🙏

@fabb
Copy link
Author

fabb commented Jan 8, 2024

yes it's fixed, thanks!

@fabb fabb closed this as completed Jan 8, 2024
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

6 participants