TypeScript 2.1 now supports object spread/rest, so no workarounds are needed anymore!
TypeScript s
A getter like this could work:
class Link extends React.Component<{
textToDisplay: string;
} & React.HTMLAttributes> {
static propTypes = {
textToDisplay: PropTypes.string;
}
private get HtmlProps(): React.HTMLAttributes {
return Object.fromEntries(
Object.entries(this.props)
.filter(([key]) => !Object.keys(Link.propTypes).includes(key))
);
}
public render():JSX.Element {
return (
{this.props.textToDisplay}
);
}
}