Alias a genType export?

Hey folks, I’ve got a module file named ElemNode.res in which I define a type t per the ReScript convention, and a bunch of functions which operate on this type t. I’m using genType to provide TypeScript support for my end users (I’m writing a library), which is great, but I’m wondering if I can write an alias in ReScript to define how these types will be named in the exported TypeScript. For example, right now my .gen.ts files all have a line like:

import type {t as ElemNode_t} from './ElemNode.gen';

and then throughout the rest of the .gen.ts file we have references to ElemNode_t. I’m wondering if it would be possible to choose a different name there that the TypeScript users would see. Even

import type {t as ElemNode} from './ElemNode.gen';

would be helpful.

I was hoping I’d be able to do something like this:

@unboxed
@genType.as("ElemNode")
type t = Repr(t) | Number(float)

But that doesn’t appear to propagate to the .gen.ts files.

Is there a way to do this? Thanks

2 Likes

I also ran into this the other day and was unable to make it work.

I’m getting the same result as the test case in the compiler: https://github.com/rescript-lang/rescript-compiler/blob/master/jscomp/gentype_tests/typescript-react-example/src/ExportWithRename.gen.tsx#L14

I.e. this:

@genType.as("ExportWithRename") @react.component
let make = (~s) => React.string(s)

yields:

export const make: React.ComponentType<{ readonly s: string }> = ExportWithRenameBS.ExportWithRename;

Not sure if that’s the expected behaviour or not.