This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Types.re
145 lines (106 loc) · 2.82 KB
/
Types.re
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
[@genType]
type typeWithVars('x, 'y, 'z) =
| A('x, 'y)
| B('z);
[@genType]
type optionInt = option(int);
[@genType]
let consumeOption = (x: option(int)) =>
Belt.Option.(x->(mapWithDefault(0, n => n)));
[@genType]
let consumeOption2 = (x: optionInt) =>
Belt.Option.(x->(mapWithDefault(0, n => n)));
[@genType]
let testArray = (a: array(option(int))): array(option(int)) => a;
[@genType]
type funType = int => int;
[@genType]
type myFloat = float;
[@genType]
type arrayOfStrings1 = array(string);
[@genType]
type arrayOfStrings2 = Js.Array.t(string);
[@genType]
type maybeString = Js.null_undefined(string);
[@genType]
type maybeString2 = Js.Null_undefined.t(string);
[@genType]
type peopleArray =
array({
.
"name": string,
"nickname": Js.nullable(string),
});
[@genType]
type myObj = Obj.t;
/* Defines a type which maps to `anInterestingFlowType` in `SomeFlowTypes.js` */
[@genType.import "./SomeFlowTypes"]
type anInterestingFlowType;
[@genType]
let identity = (x: anInterestingFlowType) => x;
[@genType.import "./SomeFlowTypes"]
type weekday;
[@bs.module "./SomeFlowTypes"] external saturday: weekday = "SATURDAY";
[@bs.module "./SomeFlowTypes"] external sunday: weekday = "SUNDAY";
[@bs.module "./SomeFlowTypes"] external monday: weekday = "MONDAY";
[@genType]
let isWeekend = day => day === saturday || day === sunday;
[@genType]
let testFunctionOnOptionsAsArgument = (a: option('a), foo) => foo(a);
[@genType]
type someMutableFields = {
.
[@bs.set] "mutable0": string,
"immutable": int,
[@bs.set] "mutable1": string,
[@bs.set] "mutable2": string,
};
[@genType.import "./name-with-dashes"] external foo: int => int = "foo";
[@genType.opaque]
type exportOpaqueFromVariants = Variants.weekday;
[@genType]
[@genType.as "DateKey"]
type dateKey = string;
[@genType.opaque]
[@genType.as "DateKeyOpaque"]
type dateKeyOpaque = string;
[@genType]
let testDateKey = (x: dateKey) => x;
[@genType]
let testAutoAnnotateVariants = (x: AutoAnnotate.variant) => x;
[@genType]
let testAutoAnnotateVariants2 = (x: AutoAnnotate.annotatedVariant) => x;
[@genType.opaque]
type opaqueVariant =
| A
| B;
[@genType]
[@genType.as "Filter"]
type filter = {
name: string,
values: array(string),
};
[@genType]
type twice('a) = ('a, 'a);
[@genType]
type gadt =
| F: gadt;
type objectWithCallback = {
.
"y": option({. "z": option(unit => int)}),
"x": option(unit => int),
};
[@genType]
let convertObjectWithCallback = (x: objectWithCallback) => x;
type ocaml_array('a) = array('a);
// This should be considered annotated automatically.
type someRecord = {id: int};
type instantiateTypeParameter = ocaml_array(someRecord);
[@genType]
let testInstantiateTypeParameter = (x: instantiateTypeParameter) => x;
[@genType]
type date = Js.Date.t;
[@genType]
let currentTime = Js.Date.make();
[@genType]
let optFunction = Some(() => 3);