Generate types in TypeScript with dependencies became broken TS.
davesnx opened this issue · comments
Hey @cristianoc,
I wanted to share one bug that I have been facing using genType and generating TypeScript.
Using BuckleScript 7.x and genType 3.18.0 (accordingly).
If I flag a variable with genType that has inferred a type from a dependency (in this case bs-js-collections), the output expects this library to have a gen file. I'm not sure if genType should generate those files (in my node_modules) for me or expect the lib to use genType as well.
I read about it here: https://github.com/reason-association/genType#dependent-projectslibraries but wasn't exactly sure about its behaviour with conjunction with "exportInterfaces": true
.
The same happens with Js.Re, that expects to expose a gen file.
[@genType]
let set = JsSet.fromArray([|1, 2, 3|]);
[@genType]
let regex = [%re {|/[a-zA-Z_][a-zA-Z0-9_]*/|}];
/* TypeScript file generated from Index.re by genType. */
const IndexBS = require('./Index.bs');
import {Re_t as Js_Re_t} from './Js.gen';
import {t as JsSet_t} from 'bs-js-collections/src/JsSet.gen';
export const set: JsSet_t<number> = IndexBS.set;
export const regex: Js_Re_t = IndexBS.regex;
debug info
Project root: /Users/davesnx/dev/playgrounds/try-genType-with-TS
Config language:typescript module: importPath: shims:0 entries bsVersion:7.3.2
Add Index.cmt /Users/davesnx/dev/playgrounds/try-genType-with-TS/Index.re
Translate Structure
Translate Value Binding set
fromPath path:JsSet.t typeEnv:__root__ External resolved:JsSet_t
Dependency: JsSet_t
Resolve Reason Module: JsSet
Resolve Generated Module: JsSet
Import Path: bs-js-collections/src/JsSet.gen
Translate Value Binding regex
fromPath path:Js.Re.t typeEnv:__root__ External resolved:Js_Re_t
Dependency: Js_Re_t
Resolve Reason Module: Js
Resolve Generated Module: Js
Import Path: ./Js.gen
Create Type Map for Index
Code Item: ExportValue resolvedName:set type:JsSet_t<number>
Converter type0:JsSet_t<number> converter:id
Code Item: ExportValue resolvedName:regex type:Js_Re_t
Converter type0:Js_Re_t converter:id
Replace /Users/davesnx/dev/playgrounds/try-genType-with-TS/Index.gen.tsx
I created a playground to show-case this bug: https://github.com/davesnx/try-gentype-with-ts
Thanks
This direction is not explored much at the moment. See discussion in #458.
Right, should I move this comment to that issue and close this one?
Moved to #458