Closed BrandanKing closed 1 year ago
Hey @BrandanKing , I think the bug you're referring to is that the next/link
has a required href
prop and the constraints haven't been made to handle that, this is actually something I didn't think of so thank you.
A quick fix for now is to cast the As
component to React.ElementType
:
polyRef<"button", {}, OnlyAs<"button" | "a" | typeof Link>>(({ as: As = "button", ...props }, ref) => {
const Elem = As as React.ElementType;
return <Elem ref={ref} {...props} />
});
I'll eventually fix the bug in the package myself so that you won't need this workaround in the next version, I could do it now but I'm currently figuring out the best way to do so.
On second thought, I might leave this in for a couple reasons:
polyRef
part seems odd to meas
prop be of type React.ElementType
, which would work but it might be more useful as is to give the user more control. Partial<T>
but that might lead to confusion cause the user might not expect the props to be tinkered with.After digging deeper, I realized it wasn't a bug, its a feature 😆
Hi, I am trying to use onlyAs to create a button that can have the following types
OnlyAs<'button' | 'a' | typeof Link>
where Link is next/link. However, whenever I add this I get the error'href' is declared here
. It appears that it doesn't apply unknown to typeof props