I', trying to create a react component which emulates a native html element.
Problem 1:
Allowing a valid html attribute
Example:
type TAtt = {
[key: string]: React.HTMLAttributes<HTMLElement>;
};
const NavAnyValidAttribute: React.FC<TAtt> = props => {
const { children, ...therest } = props;
return <nav {...therest}>{children}</nav>;
};
<NavAnyValidAttribute className="x">some children</NavAnyValidAttribute>;
Error
Type 'string' has no properties in common with type 'HTMLAttributes'.(2559) input.tsx(135, 3): The expected type comes from this index signature.
Problem 2:
type TProps = TAtt & {
TagName: string; //keyof JSX.IntrinsicElements - also doesn't work!;
}
const Tag: React.FC<TProps> = ({ TagName, children, ...props }) =>
React.createElement(TagName, props, children);
const Nav = <Tag {...{ TagName: 'nav' }} />;
Error: Type '{ TagName: string; }' is not assignable to type 'TAtt'. Property 'TagName' is incompatible with index signature. Type 'string' has no properties in common with type 'HTMLAttributes'.ts(2322)
Any help appreciated. thanks