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

Props not detected unless "import * as React from 'react'"

Open crobinson42 opened this issue 4 years ago • 5 comments

The TS interface/type used for a component's props are not picked up unless in the same file all of React is imported via: import * as React from 'react'.

This is a bug that needs addressing - happy to help, point me in the direction.

I stumbled across this here also:

https://github.com/strothj/react-docgen-typescript-loader/issues/10#issuecomment-535510047

crobinson42 avatar Feb 10 '21 01:02 crobinson42

Did anyone manage to resolve this issue yet?

olee avatar Jul 27 '21 09:07 olee

In my case changing the export type of the components from default export to named export fixed it.

@olee

coder966 avatar Jul 27 '21 11:07 coder966

Well that's not what I call a solution but a workaround 😅

olee avatar Aug 08 '21 10:08 olee

When React is imported via import React from 'react' this line has an additional member called intrinsicName which comes back as 'error'. The returned ts.Type is also missing the members .symbol and .aliasSymbol. ts.Type.getSymbol also returns undefined.

This lack of a symbol causes getComponentInfo to return an empty object for props because both ts.Type.getCallSignatures and ts.Type.getConstructSignatures return an empty array.

I've never delved into this part of JS/TS so my lack of knowledge is hampering my progress. I would appreciate it if someone could take this info and either run with it or provide me with a poke in the right direction. @hipstersmoothie and @pvasek have touched this area most recently (though it has been a while). Could either of you help me out?

MilesWellsSVT avatar Oct 29 '21 15:10 MilesWellsSVT

I'm looking forward to this issue too, I just recently introduce storybook in our project and I don't get the docgen working

Hideman85 avatar Jan 12 '22 13:01 Hideman85

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

github-actions[bot] avatar Jan 13 '23 10:01 github-actions[bot]

Closing this issue as obsolete.

github-actions[bot] avatar Jan 20 '23 10:01 github-actions[bot]