类型缺少属性onAuxClickCapture和onAuxClick

时间:2019-07-08 09:26:08

标签: reactjs typescript

使用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 个答案:

答案 0 :(得分:1)

我设法通过将React和类型更新为最新版本来解决该问题

npm i react@latest react-dom@latest @types/react@latest @types/react-dom@latest