Skip to content

Commit bbef1b4

Browse files
Gentype: Bring back shims documentation (#906)
1 parent aa9f61e commit bbef1b4

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

pages/docs/manual/latest/typescript-integration.mdx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,55 @@ These features are for experimentation only. They could be changed/removed any t
214214

215215
- Export object and record types as interfaces. To activate, add `"exportInterfaces": true` to the configuration. The types are also renamed from `name` to `Iname`.
216216

217+
218+
## Shims
219+
220+
A shim is a TS file that provides user-provided definitions for library types.
221+
222+
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.
223+
- Example: `Array<string>` with format: `"RescriptModule=JavaScriptModule"`
224+
225+
Configure your shim files within `"gentypeconfig"` in your [`rescript.json`]:
226+
227+
```json
228+
{
229+
"gentypeconfig": {
230+
"shims": {
231+
"Js": "Js",
232+
"ReactEvent": "ReactEvent",
233+
"RescriptPervasives": "RescriptPervasives",
234+
"ReasonReact": "ReactShim"
235+
},
236+
},
237+
}
238+
```
239+
240+
and add relevant `.shim.ts` files in a directory which is visible by ReScript e.g.
241+
242+
```
243+
├── rescript.json
244+
├── src
245+
│ ├── shims
246+
│ │ ├── Js.shim.ts
247+
│ │ ├── ReactEvent.shim.ts
248+
│ │ └── RescriptPervasives.shim.ts
249+
```
250+
251+
Here are some examples:
252+
253+
```ts
254+
// Excerpt from https://github.com/rescript-lang/rescript-compiler/blob/master/jscomp/gentype_tests/typescript-react-example/src/shims/Js.shim.ts
255+
export type Json_t = unknown;
256+
export type t = unknown;
257+
```
258+
259+
```ts
260+
// Excerpt from https://github.com/rescript-lang/rescript-compiler/tree/master/jscomp/gentype_tests/typescript-react-example/src/shims
261+
export type inputFocusEvent = React.FocusEvent<HTMLInputElement>;
262+
```
263+
264+
More complete example shims can be found [here](https://github.com/rescript-lang/rescript-compiler/blob/master/jscomp/gentype_tests/typescript-react-example/src/shims/).
265+
217266
## Deprecated features
218267

219268
Features related to generating runtimes were deprecated since v11 and should no longer be used.

0 commit comments

Comments
 (0)