TypeScript 2.1 now supports object spread/rest, so no workarounds are needed anymore!
TypeScript s
React.HtmlAttributes in the example above is now generic so I needed to extend from React.AnchorHTMLAttributes
.
Example:
import React from 'react';
type AClickEvent = React.MouseEvent;
interface LinkPropTypes extends React.AnchorHTMLAttributes {
to: string;
onClick?: (x: AClickEvent) => void;
}
class Link extends React.Component {
public static defaultProps: LinkPropTypes = {
to: '',
onClick: null,
};
private handleClick = (event: React.MouseEvent) => {
...
event.preventDefault();
history.push(this.props.to);
};
public render() {
const { to, children, ...props } = this.props;
return (
{children}
);
}
}
export default Link;