Is it possible to create a two record types that explicitly share some fields?

Is there an idiomatic way to create two record types that share some field subset?

Consider the following:

  • a customer record type that include an id field
  • a customer record type that doesn’t include an id field (which could be used for form state when creating customers)

How do folks handle this use case?

I’d love to ensure that the type used to create customers is in sync with the type used to get customers.

Currently, I’m defining my customer type without the id field, and using a tuple of (id, customer) when I need a customer with an id.

For structural types, it works this way, you can just do things like

type a = {
  ... b , 
  "extra-fileds" : ..

For nominal records, there is no such sugar, but you can embed it like this:

type a = {
   b : b , // This is one level indirection
  extra-fields : ..

What are those? Any reference link?

Docs are here Object | ReScript Language Manual

But that is documentation for objects. Is not the same term as structural types.
If he said structural typing I would have assumed objects (maybe) but types make me thing about an specific type

The documentation I linked says:

ReScript objects are like records, but:

That is what Hongbo is referring to by ‘structural types’.

1 Like

I can accept that yo have this understanding on the community lingo, but I don’t think it is reasonable to expect a newcomer to came to that conclusion.

I don’t expect newcomers to know everything, and I’m happy to provide documentation and explanations when I see questions.