When using genType for creating typescript types, whenever I reference a (supposedly) standard api, it tries to pull the type from some imaginary module
A simple example is using Promise.t or just Js.Dict.t
@genType
type state = {
promise: Promise.t<unit>,
dict: Js.Dict.t<string>,
}
It generates this TS file with imports to these modules, neither which exist:
import type {Dict_t as Js_Dict_t} from './Js.gen';
import type {t as Promise_t} from '@ryyppy/rescript-promise/src/Promise.gen';
// tslint:disable-next-line:interface-over-type-literal
export type state = { readonly promise: Promise_t<void>; readonly dict: Js_Dict_t<string> };
This leads to compilation errors when trying to bundle my library. Is there a way to coerce it to use TS’s built in Promise<void> or Record<string, string> instead?
Yes, via genType shims. I believe there was some finickiness when I was setting up shims for my work’s repo.
It’d be a pretty nice feature to be able to supply the shim inside a given rescript library to avoid this.
You can also use Js.Promise.t instead to avoid needing to write a shim. Promise.t I believe is just an alias but gentype doesn’t seem to deeply resolve those unfortunately.
I think it might be have something to do with the bsconfig -open flag. I did the same thing as the Js. with RescriptCore. and see the Js one resolves but core doesn’t
@genType
type js_dict = Js.Dict.t<string>
@genType
type dict = Dict.t<string>
/* TypeScript file generated from Demo.res by genType. */
/* eslint-disable import/first */
import type {Dict_t as Js_Dict_t} from '../src/shims/Js.shim';
import type {t as Dict_t} from './Dict.gen';
// tslint:disable-next-line:interface-over-type-literal
export type js_dict = Js_Dict_t<string>;
// tslint:disable-next-line:interface-over-type-literal
export type dict = Dict_t<string>;