reactjs - 类型中缺少属性 onAuxClickCapture 和 onAuxClick
从 React 使用 forwardRef 会产生奇怪的类型错误:
Type '{ children: ReactNode; }' is missing the following properties from type 'Pick<ILinkProps, "className" | "children" | "accept" | "acceptCharset" | "action" | ... 348 more ... | "onAuxClickCapture">': onAuxClick, onAuxClickCapture
似乎 onAuxClick 和 onAuxClickCapture 不知为何被标记为非可选项。
我的类型:
export interface ILinkProps extends Exclude<keyof HTMLProps<HTMLAnchorElement>, 'href'> {
state?: TRouteState;
queryParams?: IQueryObject;
}
以及简化部分:
const Link = forwardRef<HTMLAnchorElement, ILinkProps>((props, ref) => {
const href = getHref()
return (
<a {...props} href={href} ref={ref} >
{children}
</a>
)
})
export { Link }
答案#1
我通过将 React 和类型更新到最新版本来解决了这个问题
npm i react@latest react-dom@latest @types/react@latest @types/react-dom@latest