-
Notifications
You must be signed in to change notification settings - Fork 464
/
Copy pathType.resi
77 lines (62 loc) · 1.66 KB
/
Type.resi
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
/***
Utilities for classifying the type of JavaScript values at runtime.
*/
/**
The possible types of JavaScript values.
*/
type t = [#undefined | #object | #boolean | #number | #bigint | #string | #symbol | #function]
/**
`typeof(someValue)`
Returns the underlying JavaScript type of any runtime value.
See [`typeof`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) on MDN.
## Examples
```rescript
Console.log(Type.typeof("Hello")) // Logs "string" to the console.
let someVariable = true
switch someVariable->Type.typeof {
| #boolean => Console.log("This is a bool, yay!")
| _ => Console.log("Oh, not a bool sadly...")
}
```
*/
external typeof: 'a => t = "#typeof"
module Classify: {
/***
Classifies JavaScript runtime values.
*/
/**
An abstract type representing a JavaScript function.
See [`function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) on MDN.
*/
type function
/**
An abstract type representing a JavaScript object.
See [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) on MDN.
*/
type object
/**
The type representing a classified JavaScript value.
*/
type t =
| Bool(bool)
| Null
| Undefined
| String(string)
| Number(float)
| Object(object)
| Function(function)
| Symbol(Symbol.t)
| BigInt(bigint)
/**
`classify(anyValue)`
Classifies a JavaScript value.
## Examples
```rescript
switch %raw(`null`)->Type.Classify.classify {
| Null => Console.log("Yup, that's null.")
| _ => Console.log("This doesn't actually appear to be null...")
}
```
*/
let classify: 'a => t
}