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/supported-types.mdx
+6-6
Original file line number
Diff line number
Diff line change
@@ -26,13 +26,13 @@ ReScript values e.g. `"a"`, `"b"`, `"c"` are unchanged. So they are exported to
26
26
27
27
## Optionals
28
28
29
-
ReScript values of type e.g. `option(int)`, such as `None`, `Some(0)`, `Some(1)`, `Some(2)`, are exported to JS values `null`, `undefined`, `0`, `1`, `2`.
29
+
ReScript values of type e.g. `option<int>`, such as `None`, `Some(0)`, `Some(1)`, `Some(2)`, are exported to JS values `null`, `undefined`, `0`, `1`, `2`.
30
30
The JS values are unboxed, and `null`/`undefined` are conflated.
31
31
So the option type is exported to JS type `null` or `undefined` or `number`.
32
32
33
33
## Nullables
34
34
35
-
ReScript values of type e.g. `Js.Nullable.t(int)`, such as `Js.Nullable.null`, `Js.Nullable.undefined`, `Js.Nullable.return(0)`, `Js.Nullable.return(1)`, `Js.Nullable.return(2)`, are exported to JS values `null`, `undefined`, `0`, `1`, `2`.
35
+
ReScript values of type e.g. `Js.Nullable.t<int>`, such as `Js.Nullable.null`, `Js.Nullable.undefined`, `Js.Nullable.return(0)`, `Js.Nullable.return(1)`, `Js.Nullable.return(2)`, are exported to JS values `null`, `undefined`, `0`, `1`, `2`.
36
36
The JS values are identical: there is no conversion unless the argument type needs conversion.
37
37
38
38
## Records
@@ -44,7 +44,7 @@ Since records are immutable by default, their fields will be exported to readonl
44
44
45
45
The `@genType.as` annotation can be used to change the name of a field on the JS side of things. So e.g. `{[@genType.as "y"] x:int}` is exported as JS type `{y:int}`.
46
46
47
-
If one field of the ReScript record has option type, this is exported to an optional JS field. So for example ReScript type `{x: option(int)}` is exported as JS type `{x?: number}`.
47
+
If one field of the ReScript record has option type, this is exported to an optional JS field. So for example ReScript type `{x: option<int>}` is exported as JS type `{x?: number}`.
48
48
49
49
## Objects
50
50
@@ -53,7 +53,7 @@ A conversion is required only when the type of some field requires conversions.
53
53
54
54
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 }`.
55
55
56
-
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.
56
+
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.
57
57
58
58
Object field names follow ReScript's mangling convention (so e.g. `_type` in ReScript represents `type` in JS):
59
59
@@ -104,7 +104,7 @@ Arrays with elements of ReScript type `t` are exported to JS arrays with element
104
104
105
105
Immutable arrays are supported with the additional ReScript library
106
106
[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.
107
-
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`.
107
+
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`.
Maps the contained value using the given function.
62
-
If `Js.null_undefined('a)` contains a value, that value is unwrapped, mapped to a `'b` using the given function `a' => 'b`, then wrapped back up and returned as `Js.null_undefined('b)`.
62
+
If `Js.null_undefined<'a>` contains a value, that value is unwrapped, mapped to a `'b` using the given function `a' => 'b`, then wrapped back up and returned as `Js.null_undefined<'b>`.
63
63
64
64
```res example
65
65
let maybeGreetWorld = (maybeGreeting: Js.null_undefined<string>) =>
@@ -73,7 +73,7 @@ let iter: (t<'a>, (. 'a) => unit) => unit
73
73
```
74
74
75
75
Iterates over the contained value with the given function.
76
-
If `Js.null_undefined('a)` contains a value, that value is unwrapped and applied to the given function.
76
+
If `Js.null_undefined<'a>` contains a value, that value is unwrapped and applied to the given function.
77
77
78
78
```res example
79
79
let maybeSay = (maybeMessage: Js.null_undefined<string>) =>
@@ -86,7 +86,7 @@ let maybeSay = (maybeMessage: Js.null_undefined<string>) =>
86
86
let fromOption: option<'a> => t<'a>
87
87
```
88
88
89
-
Maps `option('a)` to `Js.null_undefined('a)`.
89
+
Maps `option<'a>` to `Js.null_undefined<'a>`.
90
90
`Some(a)` => `a`
91
91
`None` => `undefined`
92
92
@@ -102,7 +102,7 @@ let from_opt: option<'a> => t<'a>
Maps the contained value using the given function.
56
-
If `Js.null('a)` contains a value, that value is unwrapped, mapped to a `'b` using the given function `'a => 'b`, then wrapped back up and returned as `Js.null('b)`.
56
+
If `Js.null<'a>` contains a value, that value is unwrapped, mapped to a `'b` using the given function `'a => 'b`, then wrapped back up and returned as `Js.null<'b>`.
57
57
58
58
```res example
59
59
let maybeGreetWorld = (maybeGreeting: Js.null<string>) =>
@@ -67,7 +67,7 @@ let iter: (t<'a>, (. 'a) => unit) => unit
67
67
```
68
68
69
69
Iterates over the contained value with the given function.
70
-
If `Js.null('a)` contains a value, that value is unwrapped and applied to the given function.
70
+
If `Js.null<'a>` contains a value, that value is unwrapped and applied to the given function.
71
71
72
72
```res example
73
73
let maybeSay = (maybeMessage: Js.null<string>) =>
@@ -80,7 +80,7 @@ let maybeSay = (maybeMessage: Js.null<string>) =>
80
80
let fromOption: option<'a> => t<'a>
81
81
```
82
82
83
-
Maps `option('a)` to `Js.null('a)`.
83
+
Maps `option<'a>` to `Js.null<'a>`.
84
84
`Some(a)` => `a`
85
85
`None` => `empty`
86
86
@@ -96,7 +96,7 @@ let from_opt: option<'a> => t<'a>
Maps the contained value using the given function.
62
-
If `Js.null_undefined('a)` contains a value, that value is unwrapped, mapped to a `'b` using the given function `a' => 'b`, then wrapped back up and returned as `Js.null_undefined('b)`.
62
+
If `Js.null_undefined<'a>` contains a value, that value is unwrapped, mapped to a `'b` using the given function `a' => 'b`, then wrapped back up and returned as `Js.null_undefined<'b>`.
63
63
64
64
```res example
65
65
let maybeGreetWorld = (maybeGreeting: Js.null_undefined<string>) =>
@@ -73,7 +73,7 @@ let iter: (t<'a>, (. 'a) => unit) => unit
73
73
```
74
74
75
75
Iterates over the contained value with the given function.
76
-
If `Js.null_undefined('a)` contains a value, that value is unwrapped and applied to the given function.
76
+
If `Js.null_undefined<'a>` contains a value, that value is unwrapped and applied to the given function.
77
77
78
78
```res example
79
79
let maybeSay = (maybeMessage: Js.null_undefined<string>) =>
@@ -86,7 +86,7 @@ let maybeSay = (maybeMessage: Js.null_undefined<string>) =>
86
86
let fromOption: option<'a> => t<'a>
87
87
```
88
88
89
-
Maps `option('a)` to `Js.null_undefined('a)`.
89
+
Maps `option<'a>` to `Js.null_undefined<'a>`.
90
90
`Some(a)` => `a`
91
91
`None` => `undefined`
92
92
@@ -102,7 +102,7 @@ let from_opt: option<'a> => t<'a>
Maps the contained value using the given function.
68
-
If `Js.undefined('a)` contains a value, that value is unwrapped, mapped to a `'b` using the given function `a' => 'b`, then wrapped back up and returned as `Js.undefined('b)`.
68
+
If `Js.undefined<'a>` contains a value, that value is unwrapped, mapped to a `'b` using the given function `a' => 'b`, then wrapped back up and returned as `Js.undefined<'b>`.
69
69
70
70
```res example
71
71
let maybeGreetWorld = (maybeGreeting: Js.undefined<string>) =>
@@ -79,7 +79,7 @@ let iter: (t<'a>, (. 'a) => unit) => unit
79
79
```
80
80
81
81
Iterates over the contained value with the given function.
82
-
If `Js.undefined('a)` contains a value, that value is unwrapped and applied to the given function.
82
+
If `Js.undefined<'a>` contains a value, that value is unwrapped and applied to the given function.
83
83
84
84
```res example
85
85
let maybeSay = (maybeMessage: Js.undefined<string>) =>
@@ -92,7 +92,7 @@ let maybeSay = (maybeMessage: Js.undefined<string>) =>
92
92
let fromOption: option<'a> => t<'a>
93
93
```
94
94
95
-
Maps `option('a)` to `Js.undefined('a)`.
95
+
Maps `option<'a>` to `Js.undefined<'a>`.
96
96
`Some(a)` => `a`
97
97
`None` => `empty`
98
98
@@ -108,7 +108,7 @@ let from_opt: option<'a> => t<'a>
0 commit comments