How should one deal with errors from supposedly "equivalent" types?

Hello. When using rescript-webapi I’m getting this error:

This has type: Webapi__Fetch.readableStream
  Somewhere wanted:
    Webapi.ReadableStream.t (defined as Webapi__ReadableStream.t)

Shouldn’t these types be regarded as equal?

Basically I’m trying to use the “exported api” instead of “internal modules” as normally suggested and I’m wondering if this is a bug, some quirk of the system or more probably something obvious I’m missing


It has the same type But by mistake was made opaque in the interface I think if you create a PR where you expose the type in the interface file, @spyder will gladly merge it.

Thanks. I’ll try. I’ve been away from Rescritp for a while… still getting the hang of it.

ah, yes I probably made that mistake while importing it from bs-fetch. Please feel free to submit a PR :slight_smile:

Well…my fear just turned real… I don’t really understand what a opaque type is :-
I’m still learning rescript and I never use interface files… I also hate all the verbose duplication…

Do you mean the resi file also needs to expose the type like the implementation file?

This type readableStream = Webapi__ReadableStream.t instead of just type readableStream?

If it’s already defined in the res file why doesn’t the resi pick it up??

The interface defines what is public, so because it’s a “phantom” type in the interface, that controls what other modules see. Said another way, being able to omit the type implementation from the .resi is a feature to hide the implementation from other modules. This enables a lot of useful behavior, like enforcing all values of that type in the codebase be constructed through a parse function that handles edge cases. (for example)

If you’re coming from a JavaScript background, this is a new concept from just the “exported” API of a module. TypeScript kind of allows this with some leaps, although I don’t think it’s very common.

Gee…this get’s exoteric way to fast for me :-
Also not having a background in IT also doesn’t help much.
I tried looking at haskell and ocaml but the syntax alone made my head spin.
Is there any “for dummies” documentation about these type theory stuff suitable for someone way too old and dumb to learn a new syntax? Any rescript repository with standard examples?
Thanks for trying to thought… :wink:

PS: guess I’m not alone in lost land :stuck_out_tongue:
Any good books or complete feature-set advanced course on rescript? - General - ReScript Forum
Phantom Types in ReasonML. The classic definition that I’ve seen… | by Kennet Postigo | ReasonTraining | Medium

Variant primitive type alias - General - ReScript Forum

since I’m at it… Things I wish someone had explained about functional programming



Because interface file allows to hide things from implementation. So you need to explicitly define what public API your module have.

There are lot’s of types like that in the code…since it’s something so simple I’ll let him do the PR…maybe there should be a lot more changed.
All this duplication is kind 'of a bummer though :-
Are there any ideas to streamline this in the language or is it just not worth it?