You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`genType` lets you export [Reason](https://reasonml.github.io/) values and types to use in JavaScript, and import JavaScript values and types into Reason, idiomatically. Converter functions between the two representations are generated based on the type of the value. The converters can be generated in vanilla JavaScript, or in [TypeScript](https://www.typescriptlang.org/) / [Flow](https://flow.org/en/) for a type-safe idiomatic interface.
3
+
`genType` lets you export ReScript values and types to use in JavaScript, and import JavaScript values and types into ReScript, idiomatically. Converter functions between the two representations are generated based on the type of the value. The converters can be generated in vanilla JavaScript, or in [TypeScript](https://www.typescriptlang.org/) / [Flow](https://flow.org/en/) for a type-safe idiomatic interface.
4
4
In particular, conversion of [ReasonReact](https://reasonml.github.io/reason-react/) components both ways is supported, with automatic generation of the wrappers.
5
5
6
-
Here's an article describing how to use `genType` as part of a migration strategy where a tree of components is gradually converted to Reason bottom-up: [Adopting Reason: strategies, dual sources of truth, and why genType is a big deal](https://medium.com/p/c514265b466d).
6
+
Here's an article describing how to use `genType` as part of a migration strategy where a tree of components is gradually converted to ReScript bottom-up (old article containing Reason / BuckleScript): [Adopting Reason: strategies, dual sources of truth, and why genType is a big deal](https://medium.com/p/c514265b466d).
7
7
8
-
The implementation of [@genType] performs a type-directed transformation of Reason programs after [bucklescript](https://github.com/BuckleScript/bucklescript) compilation. The transformed programs operate on data types idiomatic to JS. For example, a Reason function operating on a Reason variant `type t = | A(int) | B(string)` (which is represented as custom blocks at runtime) is exported to a JS function operating on the corresponding JS object of type `{tag: "A"; value: number}
8
+
The implementation of @genType performs a type-directed transformation of ReScript programs after [bucklescript](https://github.com/BuckleScript/bucklescript) compilation. The transformed programs operate on data types idiomatic to JS. For example, a ReScript function operating on a ReScript variant `type t = | A(int) | B(string)` (which is represented as custom blocks at runtime) is exported to a JS function operating on the corresponding JS object of type `{tag: "A"; value: number}
9
9
| {tag: "B"; value: string}`.
10
10
11
11
The output of `genType` can be configured by using one of 3 back-ends: `untyped` to generate wrappers in vanilla JS, `typescript` to generate [TypeScript](https://www.typescriptlang.org/), and `flow` to generate JS with [Flow](https://flow.org/en/) type annotations.
@@ -14,41 +14,39 @@ The output of `genType` can be configured by using one of 3 back-ends: `untyped`
14
14
15
15
Let's assume we are working on a TypeScript (TS) codebase and we want to integrate a single ReasonReact component.
16
16
17
-
Firstly we want to be able to import the ReasonReact component like any other React component, secondly we also want to preserve all the Reason types in the TS type system (and convert incompatible values if necessary). **That's exactly what `genType` was made for!**
17
+
Firstly we want to be able to import the ReasonReact component like any other React component, secondly we also want to preserve all the ReScript types in the TS type system (and convert incompatible values if necessary). **That's exactly what `genType` was made for!**
18
18
19
19
First we'll set up a ReasonReact component just like this (we will assume that `genType` and `bs-platform` is already configured correctly):
Note how `genType` automatically maps the `color` variant to TS via a string
76
-
union type `color = "Red" | "Blue"`. We can seamlessly use Reason specific
77
-
data structures within TS without doing any manual transformations!
73
+
Note how `genType` automatically maps the `color` variant to TS via a string union type `color = "Red" | "Blue"`. We can seamlessly use ReScript specific data structures within TS without doing any manual transformations!
78
74
79
-
Now, within our TypeScript application, we can now import and use the React
80
-
component in following manner:
75
+
Now, within our TypeScript application, we can now import and use the React component in following manner:
We are only scratching the surface on what `genType` can actually do. For more
95
-
information, head to the [Getting Started](getting-started) section, or find relevant
96
-
topics from the sidebar !
89
+
We are only scratching the surface on what `genType` can actually do. For more information, head to the [Getting Started](getting-started) section, or find relevant topics from the sidebar !
97
90
98
91
## Development
99
92
100
-
Check out the [`genType` Github repository](https://github.com/reason-association/genType)for more infos.
93
+
For contributions, issues or questions, please refer to the [`genType` Github repository](https://github.com/reason-association/genType) or our [forum](https://forum.rescript-lang.org).
0 commit comments