rescript-association / genType

Auto generation of idiomatic bindings between Reason and JavaScript: either vanilla or typed with TypeScript/FlowType.

Home Page:https://rescript-lang.org/docs/gentype/latest/introduction

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot find module './Belt.gen' or its corresponding type declarations.

charkour opened this issue · comments

Hello,

I'm trying to integrate ReScript into an existing TypeScript project. I have set up ReScript and genType, but I am getting an error Cannot find module './coolHelpers.gen' or its corresponding type declarations. when I try to build the TypeScript app.

coolHelpers.res

@genType
let flat = (arr) => {
  Belt.List.flatten(arr)
}

coolHelpers.bs.js

// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Belt_List from "bs-platform/lib/es6/belt_List.js";

var flat = Belt_List.flatten;

export {
  flat ,
  
}
/* No side effect */

coolHelpers.gen.tsx

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


// tslint:disable-next-line:no-var-requires
const coolHelpersBS = require('./coolHelpers.bs');

import {List_t as Belt_List_t} from './Belt.gen';    // This line is throwing "Cannot find module './Belt.gen'"

export const flat: <T1>(arr:Belt_List_t<Belt_List_t<T1>>) => Belt_List_t<T1> = coolHelpersBS.flat;

Yes, this is a trivial example and I am just renaming a method from Belt, but I want to see how genType works within the development workflow. I am very new to ReScript. Thanks in advance for your help.

I came across these issues (#131, #132), but I wasn't able to resolve my issues after reading them. I have also read through the documentation but I don't see a mention of generating types of dependencies, but it seems like Belt should be able to be used in a TypeScript project while translating the project to ReScript. Maybe that is incorrect thinking. Please let me know!

In general, each library is responsible to export to JS, so the library itself would add annotations to types/functions it wants to export.
For a library like Belt, one would need to export the runtime representation it a way that makes sense for JS consumers. Or, export an opaque type (without revealing the internal representation), and provide functions on top of that.

There's currently no facility to inject annotations into an existing library.

Thanks for the clarification!

In relation to my issue, what would you suggest so I can use Belt functions in a TypeScript project while converting it to ReScript? Export an opaque type and provide functions on top of that?

Depends on the application. Lists don't really correspond to anything idiomatic on the TypeScript side, so I guess it would have to be an opaque type export with whatever function you need to call on the TypeScript side.

Alright, sounds good. This issue is me not fully understanding this new technology so I'll close this.

Thanks for your time and quick responses.