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

No props data outputted for components typed with React.FC<>

Open juzerzarif opened this issue 4 years ago • 5 comments

Hi, I have a component that looks like this

interface Props {
  a: string;
  b: number;
}

const MyComponent: React.FC<Props> = (props) => {...}

export default MyComponent

When parsing props for this component I get no props output => require('react-docgen-typescript').parse(...) returns an empty array. Changing to the following returns props as expected:

const MyComponentt = (props: Props) => {...}

Would it be possible to support the React.FC type assignment as well? That is my preferred way to type my functional components since it takes care of typing things like props.children correctly without an explicit field in the interface.

juzerzarif avatar Oct 15 '21 14:10 juzerzarif

I have the same problem, whether we can support this way

273403986 avatar Oct 27 '21 09:10 273403986

I've run into the same problem in storybook attempting to create a guide for our customized react-bootstrap components. I've yet to discover a workaround.

Potentially related issues I found when trying to resolve this problem: https://github.com/storybookjs/storybook/issues/14118 https://github.com/styleguidist/react-docgen-typescript/issues/323

This is outside my domain of expertise but if a steward of this repo could point me to a good starting place I could make an attempt at a PR.

MilesWellsSVT avatar Oct 27 '21 14:10 MilesWellsSVT

After poking around the repo a bit I've discovered several tests actually do use React.FC and are successful. #323 appears to be the culprit.

MilesWellsSVT avatar Oct 29 '21 15:10 MilesWellsSVT

Yes. I can confirm this. I had the same issue and using this import * as React from 'react'; instead of import React from 'react'; works

upalatucci avatar Feb 10 '22 15:02 upalatucci

Can confirm the solution @upalatucci provided worked for me. Thank you so much for finding that!

splunkmoody avatar Mar 28 '22 21:03 splunkmoody

There was no activity for a long time. The issue will be closed soon.

github-actions[bot] avatar Mar 29 '23 10:03 github-actions[bot]

Closing this issue as obsolete.

github-actions[bot] avatar Apr 05 '23 10:04 github-actions[bot]