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

How to filter props with a regex?

Open InamTaj opened this issue 6 years ago • 1 comments

I have performed a pretty standard integration of react-docgen-typescript-loader but it shows me all of the inherited props of the function as well. I was able to filter almost half of the props with specifying skipPropsWithoutDoc option in the webpack loader config. Now I'm still being shown the aria-* props which I need to skip. I tried placing regex in the skipPropsWithName option but to no avail.

Take a look: image

As for the filtering function, I have no idea how to specify both of my requirements (filter by regex and filter undocumented props) in the filtering function. Any ideas?

Tech Stack:

  • React v16
  • Typescript v3.1.4
  • Styled Components v9.7
  • Storybook v4
  • Babel v7

Thanks in advance for your help & time!

InamTaj avatar Nov 05 '18 12:11 InamTaj

Try this

module.exports = (baseConfig, env, config) => {
	// TypeScript support
	config.module.rules.push({
		test: /\.(ts|tsx)$/,
		include: path.resolve(__dirname, '../src'),
		use: [
			{
				loader: require.resolve('ts-loader'),
				options: {
					transpileOnly: true,
				},
			},
			{
				loader: require.resolve('react-docgen-typescript-loader'),
				options: {
					propFilter: props => props.parent && props.parent.fileName.startsWith('ui/src'),
				},
			},
		],
	})
	config.resolve.extensions.push('.ts', '.tsx')

	return config
}

For me, props.parent basename was ui/src but it might be different for you, console.log to find out.

OzairP avatar Nov 17 '18 18:11 OzairP