Replies: 2 comments 2 replies
-
I imagine we might not know what works well until we try things out. One strategy, if we think this is promising, is to try things out with a small test case, ideally end-to-end, and see how that works. It seems very possible that there could be some snags that are impossible to see in advance. This work is fairly messy, so I suggest @berekuk and yourself decide on some strategy you two like here. I'd be happy to go along with basically anything you two like for this. |
Beta Was this translation helpful? Give feedback.
-
I think we can do better than this. I'm not sure how exactly, yet, but I'll write down what I understand so far. Note: one of the reasons I don't like fake tags is then they create a run-time overhead on ReScript side. I'd strongly prefer the solution that doesn't do that. Key observation: we need tagging only for variants; for everything else the current ForTS pattern works pretty well and is entirely type-safe. First idea (probably bad):
Alternatively: @umuro, you're going to have a negative reaction about this initially, but hear me out :) maybe we could make specifically variants non-opaque? Right now we expose everything about their top-level structure anyway, in ForTS layer. So maybe we could make variants non-opaque, but keep their contents opaque. For example, Then in TypeScript layer it'd be easy for me to either:
Now, a few cases. First:
In this case we won't leak anything new to the TS side. genType would generate something like this:
Second:
This is a bit more problematic. Now the TS land will know that internally But this can be solved by type aliases! Then we'll be back to the initial example, and nothing is exposed again:
A bit more work on the Rescript side, but it's not that bad, I think... |
Beta Was this translation helpful? Give feedback.
-
Data Structure Design idea. Decoupling TypeScript and ReScript
We experienced that opaque data types are throwing off TypeScript and JavaScript. However, some data needs to be opaque. Otherwise coupling between the packages are too tight and even bug fixing is a torture because of coupling. I am still looking for a pattern that relieves both sides on the ReScript border for the future. One idea is creating fake tags and then keeping the data private. For example,
An alternative would be to specify a _type field instead of iAmMyModule. However that is error prone. Required to be set correctly for each module. iAmMyModule is unique to the module and type checking ensures that it is there.
There are many cases that correspond to inheritance and on TypeScript side severe type casting is required... So far there is no better way to have a record field to be utilized for typing in TypeScript.
So I am looking for an idea to ease life on the Rescript border... Any comments?
Beta Was this translation helpful? Give feedback.
All reactions