Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Treat optional(_) fields of object types as with records (no conversion JS <-> Reason). #48

Closed
cristianoc opened this issue Oct 7, 2018 · 1 comment

Comments

@cristianoc
Copy link
Collaborator

This type is a JS object type with a field c of Reason's option type:

[@genType]
type mix = {
  .
  "a": int,
  "b": int,
  "c":
    option({
      .
      "name": string,
      "surname": string,
    }),
};

It can be converted to a JS representation like this:

type mix = {|a:number, b:number, c?:{|name:string, surname:string|}|};

The conversion function can simply be the identity, to allow direct interop without any copying, all while using idiomatic options on the Reason side.

The constraint is on the JS type checking: the type for c ensures that it can not be null, just undefined.

cristianoc added a commit that referenced this issue Oct 7, 2018
@cristianoc
Copy link
Collaborator Author

This is in release 0.14.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant