Can't forward concrete HTMLAttributes
when using Polymorphic
component
#10912
Labels
needs triage
Issue needs to be triaged
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When trying to create a
Polymorphic
component, I usually need to make another component on top of it that has a more concrete implementation but uses some logic or styling defined in the base polymorphic component.For example, my current use case is quite simple, I have a polymorphic component that can be either a
div
or anarticle
and this is expected to act as a simple "Card" component. It has default styles but they can be overridden (using tailwind merge). Built on top of it I have another component, let's call itConcreteCardX
which is also a card with "X" specific content. This is intended to be anarticle
, so when I declare its props, I extend fromHTMLAttributes<'article'>
. Like this:I would expect this to work without any errors, but TypeScript can't assign the
{...props}
even when the only ones that are inside are theHTMLAttributes<'article'>
. If you hover over the error you get the typical undecipherable hieroglyphic that TypeScript usually vomits. A huge (180+) union type that can't be assigned toIntrinsicAttributes
. I tried understanding which parts are actually "not assignable" and the problem seems to be withAstroBuiltinAttributes
although take this with a grain of salt.I copied the error into a
txt
file (look below). You can go straight to the end of the error because all the attributes match except for the ones at the end.I am probably missing something or doing something wrong, if that's the case then forgive me. But this makes sense in my head and I don't understand why the props can't just be forwarded. It confuses me even more that according to
IntrinsicElements
bothdiv
andarticle
have the sameprops
so they shouldn't conflict in any way.A different and probably more understandable example is linked below in the minimal reproduction. The example uses
button
anda
tags to showcase the problem.What's the expected result?
Should be able to forward props to polymorphic components when the
{...props}
given are compatible with the polymorphic tag used. This means, if{...props}
is nothing else thanHTMLAttributes<'a'>
I should be able to pass them to a polymorphic<Link as="a" {...props} />
without TypeScript complaining.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-yxezbu?file=src%2Fwrapper.astro
Participation
The text was updated successfully, but these errors were encountered: