Skip to content

as prop type conflict when wrapping components that have their own as prop (e.g. Next.js Link) #5734

Closed

Description

@rcantin-w

Description

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

import NextLink from 'next/link';
import styled from 'styled-components';

const StyledLink = 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'.
<StyledLink href="/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.

Environment

  • styled-components: 6.4.0
  • next: 14.x
  • TypeScript: 5.x
  • React: 18.x / 19.x

Activity

  1. self-assigned this
    on May 14, 2026
  2. quantizor commented on May 14, 2026

    @quantizor
    Contributor

    Could you try [email protected] when you get a chance?

  3. rcantin-w commented on May 15, 2026

    @rcantin-w
    Author

    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.

  4. quantizor commented on May 16, 2026

    @quantizor
    Contributor
  5. rcantin-w commented on May 19, 2026

    @rcantin-w
    Author

    @quantizor thanks for looking into this! I've tested with the pre-release you specified and typescript looks happy/buttons behave as expected.

  6. quantizor commented on May 19, 2026

    @quantizor
    Contributor

    Awesome! Was released along with 6.4.2, thanks for the helpful bug report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions