这就是我要尝试的:
const ActionLink: typeof NavLink = ({onClick, ...props}) => {
function handleClick(ev: React.MouseEvent<HTMLAnchorElement>) {
ev.preventDefault();
if(onClick) onClick(ev);
}
return <NavLink {...props} onClick={handleClick}/>
}
我认为NavLink
只是我想要ActionLink
'继承'其所有属性并不重要。但是,当我尝试这样做typeof NavLink
时,出现此错误:
src/components/App.tsx:155:7 - error TS2739: Type '({ onClick, ...props }: ClassAttributes<HTMLAnchorElement> & AnchorHTMLAttributes<HTMLAnchorElement> & Pick<DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "media" | ... 257 more ... | "css"> & { ...; } & { ...; }) => Element' is missing the following properties from type 'StyledComponent<DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, Pick<DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "media" | ... 257 more ... | "css">, any>': withComponent, __emotion_styles
155 const ActionLink: typeof NavLink = ({onClick, ...props}) => {
~~~~~~~~~~
为什么?我如何缺少物业? ...props
是否应该全部捕获?
NavLink
是emotion styled component:
const NavLink = styled.a`
display: flex;
align-items: center;
text-decoration: none;
padding: 2px 5px;
&:hover {
background-color: #eee;
}
`;
NavLink.defaultProps = {href: ''};