You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 13, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 13, 2023. It is now read-only.
Add "import React from 'react'" statement to tsx files #342
I would love if the generated .tsx files would import React so that other libraries could take advantage of the exported types from "@types/react".
My specific use case is the integration of the tsx files with the documentation site generator docz, specifically the Props component. Where all it needs is the component definition to generate the documentation for the props of a react component. But it needs React to be imported in the tsx file ( which makes sense to me )
Here is what the docs look like when there is no import React from "react" statement in the generated .tsx files.
Here is what the docs look like when there is an import statement of React in the generated .tsx files:
I think the relevant line of code to change is this one
@hamza0867 I would rather not emit an import for react on all the .tsx files.
As a first step: #343
It only emits the import if the file exports one function component.
What's the full extent of your use case?
@cristianoc I believe that's all I need to make it work. I just need the .tsx files who use React type annotations to import react. There is another small tweak that I would love to have is to annotate react components with React.FunctionComponent instead of React.ComponentType but that is something that I will have to do on my own ( since it doesn't make sense to have all components be function components especially for backwards compatibility ).
Ok so I just changed the module resolution in tsconfig so I don't need the change from React.ComponentType to React.FunctionType.
All I need is for genType to import React in files where React is used.
@hamza0867 if this is for your attempt to publish TS libraries, would you write a few words on the outstanding blocks you have found?
I can only guess doc generation expects TS code to be in a specific format, though it would be interesting to confirm what that is.
@cristianoc Sorry for the late response. I will be setting a repository where I put everything that I found and the main blockers that I encountered ( and still encountering )
Activity
In TS, emit import react when a react component is exported.
cristianoc commentedon Dec 24, 2019
@hamza0867 I would rather not emit an import for react on all the
.tsxfiles.As a first step: #343
It only emits the import if the file exports one function component.
What's the full extent of your use case?
hamza0867 commentedon Dec 24, 2019
@cristianoc I believe that's all I need to make it work. I just need the
.tsxfiles who use React type annotations to import react. There is another small tweak that I would love to have is to annotate react components withReact.FunctionComponentinstead ofReact.ComponentTypebut that is something that I will have to do on my own ( since it doesn't make sense to have all components be function components especially for backwards compatibility ).hamza0867 commentedon Dec 24, 2019
Ok so I just changed the module resolution in tsconfig so I don't need the change from
React.ComponentTypetoReact.FunctionType.All I need is for genType to import React in files where React is used.
Thank you so much
In TS, emit import react when a react component is exported. (#343)
cristianoc commentedon Dec 26, 2019
@hamza0867 creating release 3.9.0 now.
hamza0867 commentedon Dec 27, 2019
Thank you so much
cristianoc commentedon Dec 27, 2019
@hamza0867 if this is for your attempt to publish TS libraries, would you write a few words on the outstanding blocks you have found?
I can only guess doc generation expects TS code to be in a specific format, though it would be interesting to confirm what that is.
hamza0867 commentedon Dec 30, 2019
@cristianoc Sorry for the late response. I will be setting a repository where I put everything that I found and the main blockers that I encountered ( and still encountering )