Hi,
I try rescript on a little PoC project and in order to have a chance to integrate it in typescript environments, I explore interoperability between the 2 languages.
Everything seemed to work smoothly when I bumped into an issue when handling rescript sum types on the ts side (in fact, on the transpiled js side).
I use ts-pattern in order to pattern-match on the output of a rescript function from typescript (but the exact same problem arises with a standard switch
statement).
In my case it’s based on a Belt.Result.t<'a, 'e>
.
the generated typescript (gen.ts
) gives me a
type MyResult<a,e> =
{ tag: "Ok"; value: a }
| { tag: "Error"; value: e };
so I can pattern match on it (pure typescript side) with
match(result)
.with({ tag: "Ok" }, () => ...)
.with({ tag: "Error"}, () => ...)
.exhaustive()
seemed great, typescript is happy… until I run the code : it breaks at runtime because it receives something like {"TAG":1,"_0":0}
Do you know how I can overcome this (without handling the result in rescript).
NB: I cross-posted as a comment on a similar issue on the gentype github : https://github.com/rescript-association/genType/issues/585, sorry for the noise if you saw it there too.
Best,
Matthieu