strothj / react-docgen-typescript-loader

Webpack loader to generate docgen information from Typescript React components.
Other
360 stars 47 forks source link

Too many props when extending an HTMLelement #66

Closed kimblim closed 4 years ago

kimblim commented 4 years ago

Is there any way to filter the props shown or only include the ones specifically defined in the interface, ie:

interface IButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
    variant?: ButtonVariants
    compact?: boolean
    submit?: boolean
    iconOnly?: boolean
    btnIcon?: ReactNode
}

will (obviously) also show all the props that can be set on the HTMLButtonElement, but I would like if it only shows the five defined explicitly.

kimblim commented 4 years ago

Figured it out — all it took was for me to read the documentation regarding propFilter and follow a link 🤦‍♂️

Anyways, here's a code snippet from my webpack.config.js, that works:

loader: 'react-docgen-typescript-loader', options: {
    propFilter(prop) {
        if (prop.parent) {
            return !prop.parent.fileName.includes('node_modules')
        }

        return true
    },
},