【发布时间】:2022-11-29 01:22:33
【问题描述】:
如何键入一个组件,该组件接受一个有效的 html 元素标签名称作为 prop 以动态呈现它
interface ButtonProps {
children: ReactNode;
className?: string;
as?: string; <--- ?
[key: string]: unknown;
}
const Button = forwardRef({ children, as: Component = 'button', children, ...props}: ButtonProps), ref) => (
<Component ref={ref} className={className} {...props}>
{children}
</Component>
)
当前收到打字稿错误Property 'children' does not exist on type 'IntrinsicAttributes'.,这绝对有道理。
【问题讨论】:
标签: reactjs typescript