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

Typescript: PropTypes.func is reported as 'custom' type when asserted to a more specific type

Open juzerzarif opened this issue 3 years ago • 0 comments

I have the following prop-types definition in my React component:

import PropTypes from 'prop-types';
import type { InferProps, Requireable } from 'prop-types';

const propTypes = {
  someFunc: PropTypes.func as Requireable<(a: string) => boolean>, // The type assertion helps narrow the type in the props interface
};

const MyComponent: React.FC<InferProps<typeof propTypes>> = (props) => {...}

react-docgen parses the someFunc prop as { type: { name: 'custom', raw: 'PropTypes.func as Requireable<(a: string) => boolean>' } }. While this is technically correct, func would be a more accurate type name here.

Is there a way for react-docgen to be able to narrow the type of a prop like that?

juzerzarif avatar Oct 22 '21 18:10 juzerzarif