I have this working as expected in the below example, my question is - is there anyway i can rewrite this so that i don't have to pass both a generic T and the as prop. I would ideally like to just pass the as prop and have the component's prop interface use that.
Is this possible in TypeScript?
export type Props<
T extends keyof JSX.IntrinsicElements
> = JSX.IntrinsicElements[T] & {
as?: keyof JSX.IntrinsicElements
}
export const MyComponent = <T extends keyof JSX.IntrinsicElements>({
as: Component = 'div',
}: Props<T>) => {
// Stuff
return <Component />
}
// Usage
const Anchor = () => <MyComponent<'a'> href='foo' as='a' id='bar' />