Skip to content

Commit bcfa75f

Browse files
authored
Update genType docs after the move inside the compiler. (#597)
* Update genType docs after the move inside the compiler. * Update getting-started.mdx
1 parent 7c85547 commit bcfa75f

File tree

2 files changed

+15
-36
lines changed

2 files changed

+15
-36
lines changed

pages/docs/gentype/latest/getting-started.mdx

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ canonical: "/docs/gentype/latest/getting-started"
66

77
# Getting Started
88

9-
`genType` is tightly integrated in the ReScript Compiler. It only requires minimal setup.
10-
119
## Setup
1210

13-
14-
Install the binaries via `npm` (or `yarn`):
11+
Since compiler v10.1, there's no need to install anything. For compiler 10.0 or older, install the binaries via `npm` (or `yarn`):
1512

1613
```
1714
npm install gentype --save-dev
@@ -20,8 +17,6 @@ npm install gentype --save-dev
2017
npx gentype --help
2118
```
2219

23-
**Note:** Version requirements / compatibility list can be found [here](https://github.com/rescript-association/genType#requirements).
24-
2520
Add a `gentypeconfig` section to your `bsconfig.json` (See [Configuration](#configuration) for details):
2621

2722
```
@@ -37,10 +32,6 @@ Add a `gentypeconfig` section to your `bsconfig.json` (See [Configuration](#conf
3732
}
3833
```
3934

40-
For running `genType` with ReScript via `npm` workflow, no special setup is required in `package.json`.
41-
42-
> **Note:** `rescript` will automatically detect your installed `genType` version.
43-
4435
## Configuration
4536

4637
Every `genType` powered project requires a configuration item `"gentypeconfig"`
@@ -50,7 +41,7 @@ structure:
5041
```js
5142
//...
5243
"gentypeconfig": {
53-
"language": "typescript" | "flow" | "untyped",
44+
"language": "typescript",
5445
"generatedFileExtension": ".gen.tsx",
5546
"module": "es6" | "commonjs",
5647
"shims": {
@@ -63,9 +54,7 @@ structure:
6354
- File extension used for genType generated files (defaults to `.gen.tsx`)
6455

6556
- **language**
66-
- `"typescript"` : Generate `*.gen.tsx` files written in TypeScript.
67-
- `"flow"`: Generate `*.gen.js` files with Flow type annotations.
68-
- `"untyped"`: Generate `*.gen.js` files in vanilla JavaScript.
57+
- `"typescript"` : the `language` setting is not required from compiler v10.1
6958

7059
- **module**
7160
- Module format used for the generated `*.gen.tsx` files (supports `"es6"` and `"commonjs"`)
@@ -74,17 +63,17 @@ structure:
7463
- Required only if one needs to export certain basic ReScript data types to JS when one cannot modify the sources to add annotations (e.g. exporting ReScript lists), and if the types are not first-classed in genType.
7564
- Example: `Array<string>` with format: `"RescriptModule=JavaScriptModule"`
7665

77-
## Adding Shims (TS & Flow)
66+
## Adding Shims
7867

79-
A shim is a TS / Flow file that provides user-provided definitions for library types.
68+
A shim is a TS file that provides user-provided definitions for library types.
8069

81-
Configure your shim files within `"gentypeconfig"` in your [`bsconfig.json`](https://github.com/reason-association/genType/blob/master/examples/typescript-react-example/bsconfig.json), and add relevant `.shims.js` files in a directory which is visible by ReScript e.g. [`src/shims/`](https://github.com/reason-association/genType/blob/master/examples/typescript-react-example/src/shims). An example shim to export ReactEvent can be found [here](https://github.com/reason-association/genType/blob/master/examples/typescript-react-example/src/shims/ReactEvent.shim.ts).
70+
Configure your shim files within `"gentypeconfig"` in your [`bsconfig.json`](https://github.com/rescript-lang/rescript-compiler/blob/master/jscomp/gentype_tests/typescript-react-example/bsconfig.json), and add relevant `.shims.ts` files in a directory which is visible by ReScript e.g. [`src/shims/`](https://github.com/rescript-lang/rescript-compiler/tree/master/jscomp/gentype_tests/typescript-react-example/src/shims). An example shim to export ReactEvent can be found [here](https://github.com/rescript-lang/rescript-compiler/blob/master/jscomp/gentype_tests/typescript-react-example/src/shims/ReactEvent.shim.ts).
8271

8372
## Testing the Whole Setup
8473

8574
Open any relevant `*.res` file and add `@genType` annotations to any bindings / values / functions to be used from JavaScript. If an annotated value uses a type, the type must be annotated too. See e.g. [Hooks.res](https://github.com/reason-association/genType/blob/master/examples/typescript-react-example/src/Hooks.res).
8675

87-
Save the file and rebuild the project via `npm run bs:build` or similar. You should now see a `*.gen.tsx` (for TypeScript, or `*.gen.js` for Flow) file with the same name (e.g. `MyComponent.res` -> `MyComponent.gen.tsx`).
76+
Save the file and rebuild the project via `npm run bs:build` or similar. You should now see a `*.gen.tsx` file with the same name (e.g. `MyComponent.res` -> `MyComponent.gen.tsx`).
8877

8978
Any values exported from `MyComponent.res` can then be imported from JS. For example:
9079

@@ -96,11 +85,7 @@ import MyComponent from "./components/MyComponent.gen";
9685

9786
We prepared some examples to give you an idea on how to integrate `genType` in your own project. Check out the READMEs of the listed projects.
9887

99-
**Please make sure to build genType before trying to build the examples.**
100-
101-
- [typescript-react-example](https://github.com/reason-association/genType/tree/master/examples/typescript-react-example)
102-
- [flow-react-example](https://github.com/reason-association/genType/tree/master/examples/flow-react-example)
103-
- [untyped-react-example](https://github.com/reason-association/genType/tree/master/examples/untyped-react-example)
88+
- [typescript-react-example](https://github.com/rescript-lang/rescript-compiler/tree/master/jscomp/gentype_tests/typescript-react-example)
10489

10590
## Experimental features
10691

@@ -115,7 +100,3 @@ These features are for experimentation only. They could be changed/removed any t
115100
- **in-source = true**. Currently only supports ReScript projects with [in-source generation](/docs/manual/latest/build-configuration#package-specs) and `.bs.js` file suffix.
116101

117102
- **Limited namespace support**. Currently there's limited [namespace](/docs/manual/latest/build-configuration#name-namespace) support, and only `namespace:true` is possible, not e.g. `namespace:"custom"`.
118-
119-
## Changelog
120-
121-
See [Changes.md](https://github.com/reason-association/genType/blob/master/Changes.md) for a complete list of features, fixes, and changes for each release.

pages/docs/gentype/latest/introduction.mdx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@ canonical: "/docs/gentype/latest/introduction"
66

77
# GenType
88

9-
`genType` is a code generation tool that lets you export ReScript values and types to use in JavaScript, and import JavaScript values and types into ReScript.
9+
`genType` is a code generation tool that lets you export ReScript values and types to use in TypeScript (TS), and import TS values and types into ReScript.
1010

11-
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.
11+
Converter functions between the two runtime representations are generated when required based on the type of the values.
1212
In particular, conversion of [rescript-react](/docs/react/latest/introduction) components both ways is supported, with automatic generation of the wrappers.
1313

1414
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).
1515

16-
The implementation of genType performs a type-directed transformation of ReScript programs after ReScript source code compilation. The transformed programs operate on data types idiomatic to JS.
16+
The implementation of genType performs a type-directed transformation of ReScript programs after compilation. The transformed programs operate on data types idiomatic to JS.
1717

18-
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 }
18+
For example, a ReScript function operating on a ReScript variant `type t = | A(int) | B(string)` (which is represented as custom objects with tags at runtime) is exported to a JS function operating on the corresponding JS object of type `{ tag: "A"; value: number }
1919
| { tag: "B"; value: string }`.
2020

21-
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.
22-
2321
## A Quick Example
2422

25-
Let's assume we are working on a TypeScript (TS) codebase and we want to integrate a single rescript-react component.
23+
Let's assume we are working on a TypeScript codebase and we want to integrate a single rescript-react component.
2624

2725
We want to be able to import the rescript-react component like any other React component in our existing TS code, but we also want to preserve all the ReScript types in the TS type system (and convert incompatible values if necessary).
2826

@@ -51,7 +49,7 @@ let make = (~name: string, ~color: color) => {
5149
};
5250
```
5351

54-
On a successful compile, `genType` will convert `src/MyComp.res` to a TS file called `src/MyComp.gen.ts` which will look something like this:
52+
On a successful compile, `genType` will convert `src/MyComp.res` to a TS file called `src/MyComp.gen.tsx` which will look something like this:
5553

5654
```ts
5755
// src/MyComp.gen.tsx
@@ -104,4 +102,4 @@ For detailed information, head to the [Getting Started](getting-started) or [Usa
104102
105103
## Development
106104
107-
For contributions, issues or questions, please refer to the [GitHub repository](https://github.com/reason-association/genType) or our [ReScript forum](https://forum.rescript-lang.org).
105+
Since ReScript v10.1, genType is part of the compiler's [GitHub repository](https://github.com/rescript-lang/rescript-compiler).

0 commit comments

Comments
 (0)