Skip to content
This repository was archived by the owner on Nov 13, 2023. It is now read-only.
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

Closed

Description

@hamza0867

Hi,

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.

Screenshot from 2019-12-23 13-30-14

Here is what the docs look like when there is an import statement of React in the generated .tsx files:

Screenshot from 2019-12-23 13-33-11

I think the relevant line of code to change is this one

Thank you so much

Activity

  1. cristianoc commented on Dec 24, 2019

    @cristianoc
    Collaborator

    @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?

  2. hamza0867 commented on Dec 24, 2019

    @hamza0867
    Author

    @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 ).

  3. hamza0867 commented on Dec 24, 2019

    @hamza0867
    Author

    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.

    Thank you so much

  4. cristianoc commented on Dec 26, 2019

    @cristianoc
    Collaborator

    @hamza0867 creating release 3.9.0 now.

  5. hamza0867 commented on Dec 27, 2019

    @hamza0867
    Author

    Thank you so much

  6. cristianoc commented on Dec 27, 2019

    @cristianoc
    Collaborator

    @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.

  7. hamza0867 commented on Dec 30, 2019

    @hamza0867
    Author

    @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 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions