You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
as prop type conflict when wrapping components that have their own as prop (e.g. Next.js Link) #5734
After upgrading to [email protected], wrapping components that define their own as prop (such as Next.js Link) with styled() produces TypeScript errors. The new as?: WebTarget prop exposed in 6.4.0 conflicts with the wrapped component's existing as prop type.
This is a regression from 6.3.x where this worked without issue.
Reproduction
importNextLinkfrom'next/link';importstyledfrom'styled-components';constStyledLink=styled(NextLink)` color: red;`;// TS2769: No overload matches this call.// Types of property 'as' are incompatible.// Type 'Url | undefined' is not assignable to type 'WebTarget | undefined'.<StyledLinkhref="/foo">Click</StyledLink>
Next.js Link has an as prop typed as Url (for URL aliasing), which conflicts with styled-components' as?: WebTarget (for polymorphic rendering).
Error
Type '{ children: Element; href: Url; }' is not assignable to type '{ as?: WebTarget | undefined; forwardedAs?: WebTarget | undefined; }'.
Types of property 'as' are incompatible.
Type 'Url | undefined' is not assignable to type 'WebTarget | undefined'.
Type 'UrlObject' is not assignable to type 'WebTarget | undefined'.
Type 'UrlObject' is not assignable to type 'string & {}'.
Type 'UrlObject' is not assignable to type 'string'.
Root cause
The 6.4.0 patch note says:
Expose as and forwardedAs props in React.ComponentProps extraction for styled components
This change makes as always present on styled component props. When the wrapped component already has an as prop with a different type, the two definitions conflict and TypeScript picks the incompatible WebTarget type.
In 6.3.x, as was not exposed in ComponentProps extraction, so the wrapped component's own as prop was used without conflict.
Expected behaviour
Wrapping a component that has its own as prop should preserve the original component's as type, or at minimum produce a union type that accepts both.
Thank you @quantizor ! I updated to "styled-components": "6.x-test" across our codebase, ran a typescript check and got:
[filepath] - error TS2769: No overload matches this call.
The last overload gave the following error.
Type '{ children: Element; replace?: boolean | undefined; as?: Url | undefined; onClick?: MouseEventHandler<HTMLAnchorElement> | undefined; ... 9 more ...; href: Url; }' is not assignable to type '{ as?: WebTarget | undefined; forwardedAs?: WebTarget | undefined; }'.
Types of property 'as' are incompatible.
Type 'Url | undefined' is not assignable to type 'WebTarget | undefined'.
Type 'UrlObject' is not assignable to type 'WebTarget | undefined'.
Type 'UrlObject' is not assignable to type 'string & {}'.
Type 'UrlObject' is not assignable to type 'string'.
36 <Link {...linkProps}>
~~~~
node_modules/@types/react/index.d.ts:562:9
562 (props: P): ReactNode;
~~~~~~~~~~~~~~~~~~~~~~
The last overload is declared here.
which I believe is the same as the original error. Let me know if I should test it differently.
Activity
quantizor commentedon May 14, 2026
Could you try
[email protected]when you get a chance?rcantin-w commentedon May 15, 2026
Thank you @quantizor ! I updated to
"styled-components": "6.x-test"across our codebase, ran a typescript check and got:which I believe is the same as the original error. Let me know if I should test it differently.
fix(types): accept wrapped component's own `as` type when spreading p…
quantizor commentedon May 16, 2026
@rcantin-w thank you for the additional debugging info! Please try the most recent 6.x-test when you get a chance, just pushed an update that should help with this. https://github.com/styled-components/styled-components/compare/styled-components@6.4.2-prerelease-20260514185513...styled-components@6.4.2-prerelease-20260516150535
rcantin-w commentedon May 19, 2026
@quantizor thanks for looking into this! I've tested with the pre-release you specified and typescript looks happy/buttons behave as expected.
quantizor commentedon May 19, 2026
Awesome! Was released along with 6.4.2, thanks for the helpful bug report!
fix(types): collapse polymorphic overloads to one signature so as-tar…
fix(types): permissive props for un-introspectable targets, plus as-t…
feat(types): as-target attribute autocomplete for polymorphic components