Skip to content

Commit d9f66d1

Browse files
Integrate genType as 'TypeScript Interop' chapter into main docs
1 parent fccbc06 commit d9f66d1

21 files changed

+66
-154
lines changed

data/sidebar_manual_latest.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
"browser-support-polyfills",
5454
"libraries"
5555
],
56+
"TypeScript Interop": [
57+
"gentype-introduction",
58+
"gentype-getting-started",
59+
"gentype-usage",
60+
"gentype-supported-types"
61+
],
5662
"Build System": [
5763
"build-overview",
5864
"build-configuration",
Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
---
22
id: "gentype-decorator"
3-
keywords: ["gentype", "decorator", "typescript", "flow"]
3+
keywords: ["gentype", "decorator", "typescript"]
44
name: "@genType"
55
summary: "This is the `@genType` decorator."
66
category: "decorators"
77
---
88

9-
The `@genType` decorator may be used to export ReScript values and types to JavaScript, and import JavaScript values and types into ReScript. It allows seamless integration of compiled ReScript modules in existing TypeScript, Flow, or plain JavaScript codebases, without loosing type information across different type systems.
9+
The `@genType` decorator may be used to export ReScript values and types to JavaScript, and import JavaScript values and types into ReScript. It allows seamless integration of compiled ReScript modules in existing TypeScript, or plain JavaScript codebases, without losing type information across different type systems.
1010

11-
[GenType](/docs/gentype/latest/introduction) is a code generation tool for automatically generating [TypeScript](https://www.typescriptlang.org/) / [Flow](https://flow.org/) type definitions, and JS runtime converters for non-shared ReScript values. It also features first-class support for [ReasonReact](https://reasonml.github.io/reason-react/) components.
12-
13-
**Note:** This decorator requires the `gentype` npm package to be installed and configured correctly. Please refer to genType's [Getting Started](/docs/gentype/latest/getting-started) section for more details.
11+
[GenType](/docs/manual/latest/gentype-introduction) is a code generation tool for automatically generating [TypeScript](https://www.typescriptlang.org/) type definitions, and JS runtime converters for non-shared ReScript values. It also features first-class support for [rescript-react](/docs/react/latest/introduction) components.
1412

1513
### Example
1614

17-
<CodeTab labels={["ReScript", "TypeScript Output", "Flow Output"]}>
15+
<CodeTab labels={["ReScript", "TypeScript Output"]}>
1816

1917
```res
2018
@genType
@@ -59,45 +57,8 @@ export const make: React.ComponentType<{
5957
};
6058
```
6159

62-
```js
63-
/**
64-
* @flow strict
65-
* @generated from MyComponent.res
66-
* @nolint
67-
*/
68-
/* eslint-disable */
69-
// $FlowExpectedError: Reason checked type sufficiently
70-
type $any = any;
71-
72-
// $FlowExpectedError: Reason checked type sufficiently
73-
import * as React from "react";
74-
75-
const $$toRE818596289 = { Red: 0, Blue: 1 };
76-
77-
// $FlowExpectedError: Reason checked type sufficiently
78-
import * as MyComponentBS from "./MyComponent.bs";
79-
80-
export type color = "Red" | "Blue";
81-
82-
// Type annotated function components are not checked by Flow, but typeof() works.
83-
const make$$forTypeof = function (_: {|
84-
+color: color,
85-
+name: string,
86-
|}): React$Node {
87-
return null;
88-
};
89-
90-
export type Props = {| +color: color, +name: string |};
91-
92-
export const make: typeof make$$forTypeof = function MyComponent(Arg1: $any) {
93-
const $props = { color: $$toRE818596289[Arg1.color], name: Arg1.name };
94-
const result = React.createElement(MyComponentBS.make, $props);
95-
return result;
96-
};
97-
```
98-
9960
</CodeTab>
10061

10162
### References
10263

103-
* [GenType](/docs/gentype/latest/introduction)
64+
* [GenType](/docs/manual/latest/gentype-introduction)

next.config.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ const config = {
102102
destination: "/docs/manual/v10.0.0/unboxed",
103103
permanent: true,
104104
},
105+
{
106+
source: "/docs/gentype/latest/introduction",
107+
destination: "/docs/manual/latest/gentype-introduction",
108+
permanent: true,
109+
},
110+
{
111+
source: "/docs/gentype/latest/getting-started",
112+
destination: "/docs/manual/latest/gentype-getting-started",
113+
permanent: true,
114+
},
115+
{
116+
source: "/docs/gentype/latest/usage",
117+
destination: "/docs/manual/latest/gentype-usage",
118+
permanent: true,
119+
},
120+
{
121+
source: "/docs/gentype/latest/supported-types",
122+
destination: "/docs/manual/latest/gentype-supported-types",
123+
permanent: true,
124+
},
105125
];
106126
},
107127
};

pages/docs/gentype/latest/getting-started.mdx renamed to pages/docs/manual/latest/gentype-getting-started.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: "Getting Started"
33
description: "How to get started with genType in your ReScript projects"
4-
canonical: "/docs/gentype/latest/getting-started"
4+
canonical: "/docs/manual/latest/gentype-getting-started"
55
---
66

7-
# Getting Started
7+
# GenType - Getting Started
88

99
## Setup
1010

pages/docs/gentype/latest/introduction.mdx renamed to pages/docs/manual/latest/gentype-introduction.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Introduction"
3-
description: "GenType - Interoperability between ReScript and TypeScript / Flow"
4-
canonical: "/docs/gentype/latest/introduction"
3+
description: "GenType - Interoperability between ReScript and TypeScript"
4+
canonical: "/docs/manual/latest/gentype-introduction"
55
---
66

77
# GenType
@@ -98,7 +98,7 @@ const App = () => {
9898
9999
That's it for our quick example.
100100
101-
For detailed information, head to the [Getting Started](getting-started) or [Usage](usage) section.
101+
For detailed information, head to the [Getting Started](/docs/manual/latest/gentype-getting-started) or [Usage](/docs/manual/latest/gentype-usage) section.
102102
103103
## Development
104104

pages/docs/gentype/latest/supported-types.mdx renamed to pages/docs/manual/latest/gentype-supported-types.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: "Supported Types"
3-
description: "Supported types and value convertion in GenType"
4-
canonical: "/docs/gentype/latest/supported-types"
3+
description: "Supported types and value conversion in GenType"
4+
canonical: "/docs/manual/latest/gentype-supported-types"
55
---
66

7-
# Supported Types
7+
# GenType - Supported Types
88

99
<Intro>
1010

@@ -39,7 +39,7 @@ The JS values are identical: there is no conversion unless the argument type nee
3939

4040
ReScript record values of type e.g. `{x: int}` such as `{x: 0}`, `{x: 1}`, are exported to JS values of type `{x: number}` without runtime conversion.
4141

42-
Since records are immutable by default, their fields will be exported to readonly property types in Flow/TS. Mutable fields are specified in ReScript by e.g. `{mutable mutableField: string}`.
42+
Since records are immutable by default, their fields will be exported to readonly property types in TS. Mutable fields are specified in ReScript by e.g. `{mutable mutableField: string}`.
4343

4444
The `@as` annotation can be used to change the name of a field on the JS side of things. So e.g. `{@as("y") x: int}` is exported as JS type `{y: number}`.
4545

@@ -50,14 +50,14 @@ If one field of the ReScript record has option type, this is exported to an opti
5050
ReScript object values of type e.g. `{. "x":int}` such as `{"x": 0}`, `{"x": 1}`, `{"x": 2}`, are exported as identical JS object values `{x:0}`, `{x:1}`, `{x:2}`. This requires no conversion. So they are exported to JS values of type `{x:number}`.
5151
A conversion is required only when the type of some field requires conversions.
5252

53-
Since objects are immutable by default, their fields will be exported to readonly property types in Flow/TS. Mutable fields are specified in ReScript by e.g. `{ @set "mutableField": string }`.
53+
Since objects are immutable by default, their fields will be exported to readonly property types in TS. Mutable fields are specified in ReScript by e.g. `{ @set "mutableField": string }`.
5454

5555
It is possible to mix object and option types, so for example the ReScript type `{. "x":int, "y":option<string>}` exports to JS type `{x:number, ?y: string}`, requires no conversion, and allows option pattern matching on the ReScript side.
5656

5757
## Tuples
5858

5959
ReScript tuple values of type e.g. `(int, string)` are exported as identical JS values of type `[number, string]`. This requires no conversion, unless one of types of the tuple items does.
60-
While the type of ReScript tuples is immutable, there's currently no mature enforcement in TS/Flow, so they're currenty exported to mutable tuples.
60+
While the type of ReScript tuples is immutable, there's currently no mature enforcement in TS, so they're currenty exported to mutable tuples.
6161

6262
## Variants
6363

@@ -96,7 +96,7 @@ Arrays with elements of ReScript type `t` are exported to JS arrays with element
9696

9797
Immutable arrays are supported with the additional ReScript library
9898
[ImmutableArray.res/.resi](https://github.com/reason-association/genType/tree/master/examples/typescript-react-example/src/ImmutableArray.resi), which currently needs to be added to your project.
99-
The type `ImmutableArray.t<+'a>` is covariant, and is mapped to readonly array types in TS/Flow. As opposed to TS/Flow, `ImmutableArray.t` does not allow casting in either direction with normal arrays. Instead, a copy must be performed using `fromArray` and `toArray`.
99+
The type `ImmutableArray.t<+'a>` is covariant, and is mapped to readonly array types in TS. As opposed to TS, `ImmutableArray.t` does not allow casting in either direction with normal arrays. Instead, a copy must be performed using `fromArray` and `toArray`.
100100

101101
## Functions and Function Components
102102

@@ -117,7 +117,7 @@ let make = (~name) => React.string(name);
117117

118118
## Imported Types
119119

120-
It's possible to import an existing TS/Flow type as an opaque type in ReScript. For example,
120+
It's possible to import an existing TS type as an opaque type in ReScript. For example,
121121

122122
```res
123123
@genType.import("./SomeFlowTypes") type weekday

pages/docs/gentype/latest/usage.mdx renamed to pages/docs/manual/latest/gentype-usage.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# Usage
1+
---
2+
title: "Usage"
3+
description: "GenType - Interoperability between ReScript and TypeScript"
4+
canonical: "/docs/manual/latest/gentype-usage"
5+
---
6+
7+
# GenType Usage
28

39
<Intro>
410

pages/docs/manual/latest/shared-data-types.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ Unlike most compiled-to-js languages, in ReScript, **you don't need to write dat
4141

4242
Many of these are stable, which means that you can still serialize/deserialize them as-is without manual conversions. But we discourage actively peeking into their structure otherwise.
4343

44-
These types require manual conversions if you want to export them for JS consumption. For a seamless JS/TypeScript/Flow integration experience, you might want to use [genType](https://github.com/cristianoc/gentype) instead of doing conversions by hand.
44+
These types require manual conversions if you want to export them for JS consumption. For a seamless JS/TypeScript integration experience, you might want to use [genType](https://github.com/cristianoc/gentype) instead of doing conversions by hand.

pages/docs/manual/v10.0.0/build-configuration.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Generating JS files with the `.bs.js` suffix means that, on the JS side, you can
161161
- It's immediately clear that we're dealing with a generated JS file here.
162162
- It avoids clashes with a potential `theFile.js` file in the same folder.
163163
- It avoids the need of using a build system loader for ReScript files. This + in-source build means integrating a ReScript project into your pure JS codebase **basically doesn't touch anything in your build pipeline at all**.
164-
- [genType](/docs/gentype/latest/introduction) requires `bs.js` for compiled JS artifacts. If you are using `genType`, you need to use `bs.js` for now.
164+
- [genType](/docs/manual/latest/gentype-introduction) requires `bs.js` for compiled JS artifacts. If you are using `genType`, you need to use `bs.js` for now.
165165

166166
## warnings
167167

pages/docs/manual/v9.0.0/build-configuration.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Generating JS files with the `.bs.js` suffix means that, on the JS side, you can
157157
- It's immediately clear that we're dealing with a generated JS file here.
158158
- It avoids clashes with a potential `theFile.js` file in the same folder.
159159
- It avoids the need of using a build system loader for ReScript files. This + in-source build means integrating a ReScript project into your pure JS codebase **basically doesn't touch anything in your build pipeline at all**.
160-
- [genType](/docs/gentype/latest/introduction) requires `bs.js` for compiled JS artifacts. If you are using `genType`, you need to use `bs.js` for now.
160+
- [genType](/docs/manual/latest/gentype-introduction) requires `bs.js` for compiled JS artifacts. If you are using `genType`, you need to use `bs.js` for now.
161161

162162
## warnings
163163

pages/docs/react/latest/introduction.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ All our documented examples can be compiled in our [ReScript Playground](/try) a
1818
- Comes with all essential React APIs for building production ready apps (`useState`, `useReducer`, `useEffect`, `useRef`,...)
1919
- No component class API (all ReScript & React codebases are built on function components & hooks)
2020
- Strong level of type safetiness and type inference for component props and state values
21-
- [GenType](/docs/gentype/latest/introduction) support for importing / exporting React components in TypeScript codebases
21+
- [GenType](/docs/manual/latest/gentype-introduction) support for importing / exporting React components in TypeScript codebases
2222

2323
> **This documentation assumes basic knowledge about ReactJS.**
2424
>

pages/docs/react/v0.10.0/introduction.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ All our documented examples can be compiled in our [ReScript Playground](/try) a
1818
- Comes with all essential React APIs for building production ready apps (`useState`, `useReducer`, `useEffect`, `useRef`,...)
1919
- No component class API (all ReScript & React codebases are built on functional components & hooks)
2020
- Strong level of type safetiness and type inference for component props and state values
21-
- [GenType](/docs/gentype/latest/introduction) support for importing / exporting React components in Flow and TypeScript codebases
21+
- [GenType](/docs/manual/latest/gentype-introduction) support for importing / exporting React components in Flow and TypeScript codebases
2222

2323
> **This documentation assumes basic knowledge about ReactJS.**
2424
>

pages/docs/react/v0.11.0/introduction.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ All our documented examples can be compiled in our [ReScript Playground](/try) a
1818
- Comes with all essential React APIs for building production ready apps (`useState`, `useReducer`, `useEffect`, `useRef`,...)
1919
- No component class API (all ReScript & React codebases are built on function components & hooks)
2020
- Strong level of type safetiness and type inference for component props and state values
21-
- [GenType](/docs/gentype/latest/introduction) support for importing / exporting React components in TypeScript codebases
21+
- [GenType](/docs/manual/latest/gentype-introduction) support for importing / exporting React components in TypeScript codebases
2222

2323
> **This documentation assumes basic knowledge about ReactJS.**
2424
>

scripts/extract-tocs.mjs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -274,32 +274,6 @@ const createReactToc = (version) => {
274274
fs.writeFileSync(TARGET_FILE, JSON.stringify(toc), "utf8");
275275
};
276276

277-
const createGenTypeToc = () => {
278-
const MD_DIR = path.join(__dirname, "../pages/docs/gentype/latest");
279-
const SIDEBAR_JSON = path.join(
280-
__dirname,
281-
"../data/sidebar_gentype_latest.json"
282-
);
283-
const TARGET_FILE = path.join(
284-
__dirname,
285-
"../index_data/gentype_latest_toc.json"
286-
);
287-
288-
const sidebarJson = JSON.parse(fs.readFileSync(SIDEBAR_JSON));
289-
290-
const FILE_ORDER = Object.values(sidebarJson).reduce((acc, items) => {
291-
return acc.concat(items);
292-
}, []);
293-
294-
const files = glob.sync(`${MD_DIR}/*.?(js|md?(x))`);
295-
const ordered = orderFiles(files, FILE_ORDER);
296-
297-
const result = ordered.map((filepath) => processFile(filepath, sidebarJson));
298-
const toc = createTOC(result);
299-
300-
fs.writeFileSync(TARGET_FILE, JSON.stringify(toc), "utf8");
301-
};
302-
303277
const createCommunityToc = () => {
304278
const MD_DIR = path.join(__dirname, "../pages/community");
305279
const SIDEBAR_JSON = path.join(__dirname, "../data/sidebar_community.json");
@@ -344,5 +318,4 @@ createReasonCompilerToc();
344318
createReactToc("latest");
345319
createReactToc("v0.10.0");
346320
createReactToc("v0.11.0");
347-
createGenTypeToc();
348321
createCommunityToc();

src/DocsOverview.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let default = (~showVersionSelect=true) => {
3636
let ecosystem = [
3737
("Package Index", "/packages"),
3838
("rescript-react", "/docs/react/latest/introduction"),
39-
("GenType", "/docs/gentype/latest/introduction"),
39+
("GenType", "/docs/manual/latest/gentype-introduction"),
4040
("Reanalyze", "https://github.com/reason-association/reanalyze"),
4141
]
4242

src/common/App.res

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ let make = (props: props): React.element => {
136136
}
137137
| {base: ["docs", "reason-compiler"], version: Latest} =>
138138
<ReasonCompilerDocsLayout> content </ReasonCompilerDocsLayout>
139-
| {base: ["docs", "gentype"], version: Latest} =>
140-
<GenTypeDocsLayout frontmatter={component->frontmatter}> content </GenTypeDocsLayout>
141139
// common routes
142140
| {base} =>
143141
switch Belt.List.fromArray(base) {

src/common/Constants.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let languageManual = version => {
2020
let ecosystem = [
2121
("Package Index", "/packages"),
2222
("rescript-react", "/docs/react/latest/introduction"),
23-
("GenType", "/docs/gentype/latest/introduction"),
23+
("GenType", "/docs/manual/latest/gentype-introduction"),
2424
("Reanalyze", "https://github.com/reason-association/reanalyze"),
2525
]
2626

src/components/Navigation.res

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ module DocsSection = {
168168
description: "Reference for all language features",
169169
href: `/docs/manual/${version}/introduction`,
170170
isActive: url => {
171-
switch url.base {
172-
| ["docs", "manual"] => true
171+
switch url.fullpath {
172+
| ["docs", "manual", _, fragment] => !(fragment->Js.String2.startsWith("gentype"))
173173
| _ => false
174174
}
175175
},
@@ -189,11 +189,11 @@ module DocsSection = {
189189
{
190190
imgSrc: "/static/[email protected]",
191191
title: "GenType",
192-
description: "Seamless TypeScript & Flow integration",
193-
href: "/docs/gentype/latest/introduction",
192+
description: "Seamless TypeScript integration",
193+
href: "/docs/manual/latest/gentype-introduction",
194194
isActive: url => {
195-
switch url.base {
196-
| ["docs", "gentype"] => true
195+
switch url.fullpath {
196+
| ["docs", "manual", _, fragment] => fragment->Js.String2.startsWith("gentype")
197197
| _ => false
198198
}
199199
},

0 commit comments

Comments
 (0)