After adding ReasonML to a React-Native typeScript codebase, I found that only a single type was generated by @genType, even though these two functions were transpiled by BuckleScript successfully. How to fix this problem?
reasonSum.re
[@genType]
let reasonSum = (a, b) => a + b;
let reasonSum2 = (a, b) => a + b;
reasonSum.gen.tsx
/* TypeScript file generated from reasonSum.re by genType. */
/* eslint-disable import/first */
// tslint:disable-next-line:no-var-requires
const Curry = require('bs-platform/lib/es6/curry.js');
// tslint:disable-next-line:no-var-requires
const reasonSumBS = require('./reasonSum.bs');
export const reasonSum: (a:number, b:number) => number = function (Arg1: any, Arg2: any) {
const result = Curry._2(reasonSumBS.reasonSum, Arg1, Arg2);
return result
};
bsconfig.json
{
"name": "reason-in-react-typescript",
"sources": [
{
"dir": "./reason",
"subdirs": true
}
],
"package-specs": [
{
"module": "es6-global",
"in-source": true
}
],
"bs-dependencies": [
"@glennsl/bs-json",
"bs-fetch"
],
"suffix": ".bs.js",
"namespace": true,
"refmt": 3,
"gentypeconfig": {
"language": "typescript",
"module": "es6",
"importPath": "relative",
"shims": {
"Js": "Js",
"React": "ReactShim",
"ReactEvent": "ReactEvent",
"ReasonPervasives": "ReasonPervasives",
"ReasonReact": "ReactShim"
},
"debug": {
"all": false
},
"exportInterfaces": false
}
}
In general, an attribute attached to a single item all only apply to that item. It's possible to make the attribute stand-alone by not associating it with a specific item, which might be interpreted as being associated with the module it's contained in, but I don't think genType
supports that. Instead it seems you'll have to add an attribute to each item you want to export:
[@genType]
let reasonSum = (a, b) => a + b;
[@genType]
let reasonSum2 = (a, b) => a + b;