Skip to content

"as" polymorphic prop returns incorrect type #1414

@EricWVGG

Description

@EricWVGG

Environment

  • Linaria version: 6.2
  • Node.js version: 18.19.0
  • OS: MacOS 14.5
  • "next-with-linaria": "^0.7.0"

Description

I'm migrating from Styled-Components to Linaria. So far pretty great! However I think I've found a minor typing issue.

I have a Button component that I frequently use as an anchor tag thusly…

<Button onClick={doSomething} >This is rendered as a button tag</Button>
<Button as="a" href="/" >This is rendered as an anchor tag</Button>

I was pleased to see that this basically works — the browser does correctly render an <a> tag in the markup, the link functions, cool. However, Typescript complains about the href attribute. The type of the component is still returned as StyledComponent<ClassAttributes<HTMLButtonElement> & ButtonHTMLAttributes<HTMLButtonElement> & Record<never, unknown>>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug report 🦗Issue is probably a bug, but it needs to be checkedneeds: complete repro 🖥️Issue need to have complete repro providedneeds: triage 🏷Issue needs to be checked and prioritized

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions