I am trying to explore as well as learn the possibility of integrating ReScript into an existing Node/TypeScript backend project. Since, the project closely follows Hexagonal architecture, I feel ReScript is a nice fit there considering the types are defined in the domain layer and persistence and API layer simply implement those.
I started with a very simple type.
@genType
type node = {
id: string,
name: string,
description: string,
key: int,
createdAt: Js.Date.t,
// PROBLEM:
updatedAt: Date.t,
elm: Dom.element,
parent: Dom.document,
}
This produced following TypeScript code:
/* TypeScript file generated from ContextType.res by genType. */
/* eslint-disable */
import type { document as Dom_document } from './Dom.gen.js';
import type { element as Dom_element } from './Dom.gen.js';
import type { t as Date_t } from './Date.gen.js';
export type node = {
readonly id: string;
readonly name: string;
readonly description: string;
readonly key: number;
readonly createdAt: Date;
readonly updatedAt: Date_t;
readonly elm: Dom_element;
readonly parent: Dom_document
};
The good thing here is that Js.Date.t
is cleanly mapped to native JS/TS Date
type whereas other types Date.t
Dom.element
Dom.document
try to map to some non-existent types. Additionally, it seems to be importing these types from some non existent relative files ./Date.gen.js
, ./Dom.gen.js
;
Is there a way around this problem? And, are there any more pitfalls that I should be aware of before attempting to migrate the core business logic from TS to ReScript?