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: misc_docs/syntax/decorator_unboxed.mdx
+6-29Lines changed: 6 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -6,35 +6,10 @@ summary: "This is the `@unboxed` decorator."
6
6
category: "decorators"
7
7
---
8
8
9
-
The `@unboxed` decorator provides a way to unwrap **variant** constructors that have a *single* argument, or **record** objects that have a *single* field.
9
+
The `@unboxed` decorator provides a way to unwrap **variant** constructors
10
+
that have a *single* argument, or **record** objects that have a *single* field.
10
11
11
-
For example, consider the following code:
12
-
13
-
<CodeTablabels={["ReScript", "JS Output"]}>
14
-
15
-
```res
16
-
type name = Name(string)
17
-
let studentName = Name("Joe")
18
-
19
-
type greeting = {message: string}
20
-
let hi = {message: "hello!"}
21
-
```
22
-
23
-
```js
24
-
var studentName =/* Name */{
25
-
_0:"Joe"
26
-
};
27
-
28
-
var hi = {
29
-
message:"hello!"
30
-
};
31
-
```
32
-
33
-
</CodeTab>
34
-
35
-
When compiled to JavaScript, these values are represented as objects.
36
-
37
-
If we now add the `@unboxed` decorator, the object wrappers are removed from the JavaScript output:
12
+
### Example
38
13
39
14
<CodeTablabels={["ReScript", "JS Output"]}>
40
15
@@ -55,4 +30,6 @@ var hi = "hello!";
55
30
56
31
</CodeTab>
57
32
58
-
See the [Unboxed](/docs/manual/latest/unboxed) section for more details.
0 commit comments