Hi, is it possible to type the props that as is required to accept? Without this it is easy to pass in an as prop that is not compatible with the polymorphic component. Thanks.
Using the heading example in the readme (also see this codesandbox for a live reproduction):
// Heading from readme:
function Heading<
T extends React.ElementType = typeof HeadingDefaultElement
>({ as, color, style, ...restProps }: HeadingProps<T>) {
const Element: React.ElementType = as || HeadingDefaultElement;
return <Element style={{ color, ...style }} {...restProps} />;
}
const MyHeading: React.FC<{}> = ({ children }) => <h1>{children}</h1>;
function App() {
return (
<>
<Heading as={MyHeading} color="green">
This should result in a type error because MyHeading doesn't accept a style prop,
but typescript thinks it's fine even though it doesn't work.
</Heading>
{/* this errors because MyHeading doesn't accept a style prop
<MyHeading style={{ color: "green" }}>MyHeading</MyHeading>
*/}
</>
);
}
Hi, is it possible to type the props that
asis required to accept? Without this it is easy to pass in anasprop that is not compatible with the polymorphic component. Thanks.Using the heading example in the readme (also see this codesandbox for a live reproduction):