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
Copy file name to clipboardExpand all lines: pages/docs/gentype/latest/getting-started.mdx
+7-15Lines changed: 7 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Add a `gentypeconfig` section to your `bsconfig.json` (See [Configuration](#conf
26
26
27
27
```
28
28
"gentypeconfig": {
29
-
"language": "untyped",
29
+
"language": "typescript",
30
30
"shims": {},
31
31
"debug": {
32
32
"all": false,
@@ -35,22 +35,14 @@ Add a `gentypeconfig` section to your `bsconfig.json` (See [Configuration](#conf
35
35
}
36
36
```
37
37
38
-
For running `gentype` with ReScript via `npm` workflow, add following script in your `package.json`:
39
-
40
-
```
41
-
scripts: {
42
-
"build": "rescript",
43
-
"clean": "rescript clean"
44
-
}
45
-
```
38
+
For running `genType` with ReScript via `npm` workflow, no special setup is required in `package.json`.
46
39
47
40
> **Note:**`rescript` will automatically detect your installed `genType` version.
48
41
49
42
## Configuration
50
43
51
44
Every `genType` powered project requires a configuration item `"gentypeconfig"`
52
-
at top level in the project's `bsconfig.json`. (The use of a separate file
53
-
`gentypeconfig.json` is being deprecated). The configuration has following
45
+
at top level in the project's `bsconfig.json`. The configuration has following
54
46
structure:
55
47
56
48
```js
@@ -70,12 +62,12 @@ structure:
70
62
-`"untyped"`: Generate `*.gen.js` files in vanilla JavaScript.
71
63
72
64
-**shims**
73
-
- e.g. `Array<string>` with format: `"RescriptModule=JavaScriptModule"`
74
-
-Required to export certain basic ReScript data types to JS when one cannot modify the sources to add annotations (e.g. exporting ReScript lists)
65
+
-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.
66
+
-Example: `Array<string>` with format: `"RescriptModule=JavaScriptModule"`
75
67
76
68
## Adding Shims (TS & Flow)
77
69
78
-
A shim is a TS / Flow file that provides user-defined definitions for library types.
70
+
A shim is a TS / Flow file that provides user-provided definitions for library types.
79
71
80
72
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).
81
73
@@ -97,8 +89,8 @@ We prepared some examples to give you an idea on how to integrate `genType` in y
97
89
98
90
**Please make sure to build genType before trying to build the examples.**
Copy file name to clipboardExpand all lines: pages/docs/gentype/latest/supported-types.mdx
-6Lines changed: 0 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -137,12 +137,6 @@ For example:
137
137
let exampleFunction = (~_type) => "type: " ++ _type
138
138
```
139
139
140
-
## Record Components
141
-
142
-
ReasonReact record components with props of ReScript types `t1`, `t2`, `t3` are exported as reactjs components with props of the JS types corresponding to `t1`, `t2`, `t3`. The annotation is on the `make` function: `[@genType] let make ...`.
143
-
144
-
A file can export many components by defining them in sub-modules. The toplevel component is also exported as default.
145
-
146
140
## Imported Types
147
141
148
142
It's possible to import an existing TS/Flow type as an opaque type in ReScript. For example,
**NOTE:** the value `component` must also be defined, above `make` in the same module (also in the case of components defined in nested modules).
89
-
90
-
91
-
To import and wrap a ReactJS component for use by ReasonReact, the type of the `make` function is the only information required:
92
-
93
-
```res
94
-
@genType.import("./MyBanner") /* Module with the JS component to be wrapped. */
95
-
/* The make function will be automatically generated from the types below. */
96
-
external make:
97
-
(~show: bool, ~message: option<message>=?, 'a) =>
98
-
ReasonReact.component<
99
-
ReasonReact.stateless,
100
-
ReasonReact.noRetainedProps,
101
-
ReasonReact.actionless,
102
-
> =
103
-
"make";
104
-
```
105
-
106
-
The type of `make` must have a named argument for each prop in the JS component. Optional props have option type. The `make` function will be generated by `genType`.
107
-
108
-
This assumes that the JS component was exported with a default export. In case of named export, use e.g. `@genType.import(("./MyBanner", "componentName"))`. To import a nested component, use e.g. `@genType.import(("./MyBanner", "Some.Nested.component"))`.
109
-
110
74
## Interface (.resi) and Implementation (.res) files
111
75
112
-
If both `Foo.resi` and `Foo.res` exist, the annotations are taken from `Foo.resi`.
76
+
If both `Foo.resi` and `Foo.res` exist, the annotations are taken from `Foo.resi`. The same happens with local modules: if present, the module type gets precedence.
113
77
114
78
The behaviour can be overridden by adding annotation `@genType.ignoreInterface` at the top of `Foo.resi`. Use case: expose implementation details to JS but not to ReScript.
0 commit comments