Skip to content

gentype inconsistency with functions vs. react component #7466

Open
@jmagaram

Description

@jmagaram

See https://github.com/jmagaram/gentype-issue.

Look at TestModule.gen.tsx. Notice that the function result from the mathOperation is type a for the React component, which is a type error. There is no such problem with the makeRegular.

This is a simplified version of a real problem I'm having in my code. My React component is generic and a few of the props all rely on the same type param. I'm just a hobby programmer and run into problems with gentype. Does anyone actually use gentype in the real world? I'm really hoping the improvement in V12 happens with .d.ts file output.

export const make: React.ComponentType<{
  readonly initial: any;
  readonly mathOperation: (_1: any, _2: any) => a;
  readonly serialize: (_1: any) => string;
}> = TestModuleJS.make as any;

export const makeRegular: <a>(
  initial: a,
  mathOperation: (_1: a, _2: a) => a,
  serialize: (_1: a) => string,
) => string = TestModuleJS.makeRegular as any;

I tried this kind of .resi and the .gen.tsx does the right thing. BUT I can't figure out how to actually use it without a functor. So it is generic, but is a hassle to use.

type zebra

@react.component @genType
let make: (
  ~initial: zebra,
  ~mathOperation: (zebra, zebra) => zebra,
  ~serialize: zebra => string,
) => Jsx.element

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