Skip to content

Missing type import in generated TypeScript File with genType for React Components #6624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
WhyThat opened this issue Feb 9, 2024 · 1 comment
Labels
stale Old issues that went stale

Comments

@WhyThat
Copy link

WhyThat commented Feb 9, 2024

Hey!

I've identified an issue with genType with React component

Explaination

I have two components which are globally the same

// Working.res
type t = string
type props = {children: React.element, t: t}
@genType
let make = ({children}: props) => {
  <div> children </div>
}

And

// NotWorking.res
type not_imported = string

type props = {children: React.element, not_imported: not_imported}

@genType
let make = ({children}: props) => {
  children
}

When compiling these components the types generated by @genType are good 👌

But if I want to export then from another file like that:

// index.res
@genType
let \"NotWorking" = NotWorking.make

@genType
let \"Working" = Working.make

The index.gen.tsx generated by genType is:

/* TypeScript file generated from index.res by genType. */

/* eslint-disable */
/* tslint:disable */

import * as indexJS from './index.res.js';

import type {Jsx_element as PervasivesU_Jsx_element} from '../src/shims/PervasivesU.shim';

import type {props as NotWorking_props} from './NotWorking.gen';

import type {props as Working_props} from './Working.gen';

export type workaroundProps = NotWorking_props;

export const NotWorking: React.ComponentType<{ readonly children: React.ReactNode; readonly not_imported: not_imported }> = indexJS.NotWorking as any;

As you can see the type not_imported is not imported

Reproduction

A minimal reproduction example is available in this GitHub repository: gentype-error-reproduction. It outlines the setup and demonstrates the specific steps needed to observe the problematic behavior.

Workaround

By redefining the props within the index.res file as follows, I found a temporary solution:

type workaroundProps = NotWorking.props
@genType let \"Workaround": workaroundProps => React.element = NotWorking.make

This approach forces a correct import of types in the generated TypeScript file, avoiding the issue temporarily.

Question

Is the identified workaround the recommended approach to this issue, or does it highlight a bug within genType that needs addressing?

Have a great day :)

Copy link

github-actions bot commented Feb 4, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Old issues that went stale label Feb 4, 2025
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Old issues that went stale
Projects
None yet
Development

No branches or pull requests

1 participant