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

API design and language cleanup. #70

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

API design and language cleanup. #70

cristianoc opened this issue Oct 21, 2018 · 1 comment
Labels
enhancement New feature or request

Comments

@cristianoc
Copy link
Collaborator

cristianoc commented Oct 21, 2018

Trying to consolidate some common themes emerging in received feedback, and to define the language to talk about them. The goal here is to have a cleanup pass on outstanding questions, API design, and documentation.

Terms

Type and Value.

Import and Export something.

Modules and Classes.

Renaming when e.g. type is a keyword, or A is capitalized, or using a different name for binding is useful.

Immutable Fields of objects and records are immutable by default, and arrays are opt-in immutable by using ImmutableArray.t.

Type Expansion see below.

Principles

  1. If you’ve created some binding in one module, you should be able to use it from another module. (Instead of creating the same binding once again).
    Related: @ybybzj’s issue Generate opaque types corresponding to an existing Flow/TS type. #63.

  2. It should be clear whether an annotation means that you’re importing or exporting something.
    Values can be either imported or exported, not both. Values already have a special syntax for export: the external keyword.
    Types can be imported, exported, but perhaps even both (e.g. import a JS type that is a string, and use it as a string in Reason, one needs to check that the two representations are consistent). The information on whether a type is imported or exported must be in the annotation.

  3. If in doubt, the default meaning of an annotation is export. But, one could have also an explicit annotation. E.g. for types, export is the default, but one could add a @genType.export annotation too, to be super clear.

  4. If an exported type is defined in terms of another type which is not annotated, what happens should be clear. Type expansion could be interesting to have, where types are expanded (i.e. inlined) until one reaches an annotated type, or a cycle. Also, should type expansion work across modules, and is that easy to implement? See also Support for tuples #71.

Problems and solutions

Q: How can I add annotations if I don't have, or can’t change, the code?

Example1: standard library, Belt, ReasonReact. (For now: shims).

Example2: @MarcelCutts on "exporting a type generated by GraphQL”. Or a type coming from invoking a functor.
Progress can be made on the second example by looking into Type Expansion.
Related: #64

Q: What about JS classes?

There’s not a clear answer for now.
Related: @ybybzj’s issue #63

Q: What should Modules export to, and with what representation, in the JS world?

There's an object-like quality in the values they contain, but a namespace-like quality in the types they contain.
Related: #42
Related: #41

cristianoc added a commit that referenced this issue Oct 21, 2018
cristianoc added a commit that referenced this issue Oct 21, 2018
cristianoc added a commit that referenced this issue Oct 21, 2018
Following the cleanup plan on import/export in #70.
cristianoc added a commit that referenced this issue Oct 21, 2018
…ules.

Principle 1 is from: #70.

This simplifies a bunch of examples.

In particular, those discusse in #63.
cristianoc added a commit that referenced this issue Oct 23, 2018
- Clean up terminology used in README.md. Following the cleanup plan on import/export in #70.
- Implement principle 1: an imported type is also exported to other modules.
- Support tuple types.
- In Flow, keep opaque types also opaque internally, so export erros are caught early like in TS.
- Fix: Type names for types which are defined somewhere are not considered opaque.
- Fix: no conversion generated for opaque types.
- Generated code can be in a different order, because of refactoring how type declarations are processed.
cristianoc added a commit that referenced this issue Oct 23, 2018
This means that if a type is annotated wiht @genType, and used another type in its definition, the other type will also be considered as annotated.

This is currently supported within one file, and not across files.

In config. Off by default at the moment.

See “Type Expansion” in #70
cristianoc added a commit that referenced this issue Oct 23, 2018
Now types used by other annotated types, if in the same file, are consider implicitly annotated.

This implements the major new features proposed in #70.

Addresses the repro example in #64.
cristianoc added a commit that referenced this issue Oct 26, 2018
# 0.24.0
- Improved debug output and number of options, and made controllable from bsconfig.json.
- Fixed issue with import strings containig `.\directory` on Windows.
- Extended support for signatures and module types.
- Module include is supported for Type Expansion.
- First-orer modules are supported for Type Expansion.
- Functor application supported for Type Expansion.
- Annotating a type means all the types mentioned in it are also considered annotated. (Implemented via Type Expansion).
- Add support for type expansion (#70)
@cristianoc cristianoc added the enhancement New feature or request label Oct 27, 2018
cristianoc added a commit that referenced this issue Oct 29, 2018
This is the documentation part of the overall cleanup proposed in #70.
@cristianoc
Copy link
Collaborator Author

This has been incorporated in the README and code structure.

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

No branches or pull requests

1 participant