Skip to content

Button component as={Link} triggers typecheck error #1002

@shixiao

Description

@shixiao
  • I have searched the Issues to see if this bug has already been reported
  • I have tested the latest version

Steps to reproduce

  1. Go to 'this sandbox'
  2. Run task dev (which does yarn dev)

Current behavior

The second button (<Button as={Link} href="www.example.com">Toggle 2</Button>) triggers a typechecker error:

Type '{ children: string; as: ForwardRefExoticComponent<Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof InternalLinkProps> & InternalLinkProps & { ...; } & RefAttributes<...>>; href: string; }' is not assignable to type 'Pick<Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof InternalLinkProps> & InternalLinkProps & { ...; } & RefAttributes<...>, "slot" | ... 263 more ... | keyof InternalLinkProps>'.
  Types of property 'as' are incompatible.
    Type 'ForwardRefExoticComponent<Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof InternalLinkProps> & InternalLinkProps & { ...; } & RefAttributes<...>>' is not assignable to type 'Url | undefined'.typescript(2322)

Expected behavior

No typechecker error.

Context

#885 made a series of Button and ButtonProps types / interfaces generic, attempting to allow as={...}. For some reason, this is not working for as={Link}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't workingconfirmedThis bug was confirmed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions