Skip to content

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

Closed as not planned
@WhyThat

Description

@WhyThat

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleOld issues that went stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions