linaria icon indicating copy to clipboard operation
linaria copied to clipboard

"as" polymorphic prop returns incorrect type

Open EricWVGG opened this issue 1 year ago • 0 comments

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>>

EricWVGG avatar May 31 '24 20:05 EricWVGG