This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
API design and language cleanup. #70
Labels
enhancement
New feature or request
Comments
cristianoc
added a commit
that referenced
this issue
Oct 21, 2018
Following the cleanup plan on import/export in #70.
This was referenced Oct 21, 2018
Merged
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 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
added a commit
that referenced
this issue
Oct 29, 2018
This is the documentation part of the overall cleanup proposed in #70.
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.
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, orA
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
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.
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.
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.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
The text was updated successfully, but these errors were encountered: