A question about ReasonML/Rescript/OCaml on JS.
How do you deal with the lack of structure inheritance?

I'm mainly a backend dev with OOP background so I'm probably not seeing something.

But at work, our frontend has a lot of types (TS) like this:

```
type Client = BaseClient & {
assignees: Actor[]
}
```

We use these for types that we get from API (a base type + some additional fields).

How would you model something like that in Reason/Rescript/OCaml?

#reasonml #Rescript #OCaml

What I think about it after some digging and poking around Melange and Rescript playgrounds:

1. Rescript can "combine" both object types and record types. If you have `type t1` and `type t2`, a `type t = {...t1, ...t2}` will have fields from both t1 and t2. But you can't put a variable of `type t` where a `t1` or `t2` is expected. At least this doesn't work: https://tinyurl.com/yv7j24mj

{cont}
#reasonml #Rescript #OCaml

ReScript Playground

Try ReScript in the browser

ReScript Documentation

2. OCaml has proper OOP, with inheritance, method overrides, all that stuff. But, unlike records, it's not easy to bind to JS objects, I think.
3. Somewhere on Rescript forum I saw something like "prefer explicitness to DRY". Which I guess makes sense?

#reasonml #Rescript #OCaml

So basically, it looks like the best way would be to:
1. Declare DTO types with *all* the fields (maybe using combining types if you use Rescript)
2. From these combined types, manually construct "entity" types. If needed, you can use composition (through records, tuples, etc) to combine multiple entities together.

#reasonml #Rescript #OCaml

@art_codesmith Hmm interesting... https://rescript-lang.org/docs/manual/latest/object says that Object types (like in your playground link) support structural typing, whereas Record are nominal only.

But it seems like Rescript has repeated the mistake Python made with TypedDict, and which TypeScript usefully avoided, where extra fields on the type cause it not to match the smaller type it otherwise completely satisfies.

The TS behaviour is much more pragmatically useful IMHO.

Object | ReScript Language Manual

Interoping with JS objects in ReScript

ReScript Documentation
@anentropic I poked around it a little bit and found out that if I replace `(a: a)` with just `a` in the function definition, it works. It basically works for any object that has `"x": int` and `"y": float` fields.
So yeah, structural typing.