react-docgen-typescript icon indicating copy to clipboard operation
react-docgen-typescript copied to clipboard

Props cannot extend from an interface using `Pick`

Open cwmacdon opened this issue 9 years ago • 2 comments

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

cwmacdon avatar Jun 08 '17 18:06 cwmacdon

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

ESWAT avatar Sep 05 '17 15:09 ESWAT

Release v1.0.2 which has just been published should fix this issue.

pvasek avatar Sep 09 '17 08:09 pvasek