Skip to content

genType cannot "unwrap" some types with -open ReactV3 #5990

Closed
@illusionalsagacity

Description

Thank you for filing! Check list:

  • Is it a bug? Usage questions should often be asked in the forum instead.
  • Concise, focused, friendly issue title & description.
  • A minimal, reproducible example.
  • OS and browser versions, if relevant.
  • Is it already fixed in master?

I'm not really sure where this issue belongs

Given this ReScript code:

@genType
type publicAction = Foo | Bar({hello: string})

@genType
let use = () => {
  React.useCallback0(
  action =>
  switch action {
  | Foo => "Foo"
  | Bar({hello}) => hello
  })
}

JSXv3 gentype Code reproduction repository

no longer "wraps" the callback to convert the type representation from the TypeScript one to ReScript's version.

/* TypeScript file generated from Example.res by genType. */
/* eslint-disable import/first */


// @ts-ignore: Implicit any on import
import * as ExampleBS__Es6Import from './Example.bs';
const ExampleBS: any = ExampleBS__Es6Import;

import type {React_callback as ReactV3_React_callback} from '@rescript/react/src/v3/ReactV3.gen';

// tslint:disable-next-line:interface-over-type-literal
export type publicAction = "Foo" | { readonly hello: string };

export const use: () => ReactV3_React_callback<publicAction,string> = ExampleBS.use;

@rescript/react@~0.10.0 and [email protected] produce this:

/* TypeScript file generated from Example.res by genType. */
/* eslint-disable import/first */


const $$toRE3555235: { [key: string]: any } = {"Foo": 0};

// @ts-ignore: Implicit any on import
import * as ExampleBS__Es6Import from './Example.bs';
const ExampleBS: any = ExampleBS__Es6Import;

// tslint:disable-next-line:interface-over-type-literal
export type publicAction = "Foo" | { readonly hello: string };

export const use: () => (_1:publicAction) => string = function () {
  const result = ExampleBS.use();
  return function (Arg1: any) {
      const result1 = result(typeof(Arg1) === 'object'
        ? Object.assign({TAG: 0}, Arg1)
        : $$toRE3555235[Arg1]);
      return result1
    }
};

I think this related is a fairly long-standing issue with gentype where the types don't "recurse" into third-party modules to resolve / unwrap. i.e. React_callback is just a type, it can't be resolved to a function that needs to have it's arguments wrapped.

rescript-association/genType#458

I can try to see if adding gentype annotations to a locally linked @rescript/react will help, but do not have time to do this immediately--Having trouble getting the compiler going on the m1 at the moment, I can try to reproduce on an intel mac later.

I fully realize this could (and probably should) be considered better output code, but it breaks gentype usage from typescript, which is IMO fairly disruptive

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions