File tree 1 file changed +44
-0
lines changed
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ id : " tag-decorator"
3
+ keywords : ["tag", "decorator"]
4
+ name : " @tag"
5
+ summary : " This is the `@tag` decorator."
6
+ category : " decorators"
7
+ ---
8
+
9
+ The ` @tag ` decorator is used to customize the discriminator for tagged variants.
10
+
11
+ <CodeTab labels = { [" ReScript" , " JS Output" ]} >
12
+
13
+ ``` res
14
+ type mood = Happy({level: int}) | Sad({level: int})
15
+
16
+ @tag("kind")
17
+ type mood2 = Happy({level: int}) | Sad({level: int})
18
+
19
+ let mood: mood = Happy({level: 10})
20
+ let mood2: mood2 = Happy({level: 11})
21
+
22
+ ```
23
+
24
+ ``` js
25
+ let mood = {
26
+ TAG : " Happy" ,
27
+ level: 10
28
+ };
29
+
30
+ let mood2 = {
31
+ kind: " Happy" ,
32
+ level: 11
33
+ };
34
+ ```
35
+
36
+ </CodeTab >
37
+
38
+ Notice the different discriminators in the JS output: ` TAG ` in ` mood ` vs ` kind ` in ` mood2 ` .
39
+
40
+ Read more about [ using ` @tag ` with variants] ( variant.md#tagged-variants ) .
41
+
42
+ ### References
43
+
44
+ * [ Using ` @tag ` with variants] ( variant.md#tagged-variants )
You can’t perform that action at this time.
0 commit comments