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

"as" polymorphic prop doesn't apply correct prop types in v6 #4112

Open
nikmilson opened this issue Aug 3, 2023 · 0 comments
Open

"as" polymorphic prop doesn't apply correct prop types in v6 #4112

nikmilson opened this issue Aug 3, 2023 · 0 comments

Comments

@nikmilson
Copy link

It's great, that styled-components now provide its own types. However I believe, there's a regression in comparison to @types/styled-components. My apologies in advance if I misunderstood the concept. Otherwise if the bug will be confirmed, I might consider creating a PR with a fix.

Environment

No need, since it's generic issue applicable to all typescript environments. Code sandboxes are provided below.

Reproduction

Please give the code sandboxes a bit of time to init the environment, so the errors shown at the beginning will disappear.

Steps to reproduce

  1. Create a React component with a required prop
  2. Wrap it in styled
  3. Render the styled component, but pass another component/HTML element without the required prop via "as" polymorphic prop

Expected Behavior

When using "as" polymorphic prop a styled component should expect properties of the passed component, not originally wrapped component.

Actual Behavior

Typescript error, example from the code sandbox above:

Property 'requiredProp' is missing in type '{ children: string; as: "button"; }' but required in type 'FastOmit<Substitute<FastOmit<{ className?: string | undefined; requiredProp: string; }, never>, Substitute<{}, Omit<DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & { ...; }>>, keyof ExecutionProps>'.

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

1 participant