react-docgen-typescript
react-docgen-typescript copied to clipboard
Props cannot extend from an interface using `Pick`
The Pick operator allows us to specify a subset of properties from another interface. However this causes a parsing error in the file, and it crashes and fails to generate anything at all for this class.
export interface IButtonProps extends Pick<React.HTMLProps<HTMLInputElement>, 'onClick'|'type'> {
icon?: string
}
export class Button extends React.PureComponent<IButtonProps, {}> {
render() {
const { type, onClick, icon } = this.props;
return (
<input type={type} onClick={onClick}>
{this.props.icon
? <i className={`fa fa-${icon}`} />
: null
}
{this.props.children}
</input>
);
}
}
Gives the following error:
Error when parsing src/components/Button/Button.tsx: TypeError: Cannot read property 'parent' of undefined
So I’ve ran into this issue with a very similar example. After some debugging I realized that parsing is fine when Pick is used for just one property, but using Pick for more than one element leads to an error.
EDIT: Using 1.0.0
Release v1.0.2 which has just been published should fix this issue.