Skip to content

Commit dbc03ea

Browse files
authoredFeb 16, 2023
Docs for Type module (#32)
* Docs for Type module * fix PR comments
1 parent c43beaf commit dbc03ea

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
 

‎src/Core__Type.resi

+62
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,62 @@
1+
/***
2+
Utilities for classifying the type of JavaScript values at runtime.
3+
*/
4+
5+
/**
6+
The possible types of JavaScript values.
7+
*/
18
type t = [#undefined | #object | #boolean | #number | #bigint | #string | #symbol | #function]
29

10+
/**
11+
`typeof(someValue)`
12+
13+
Returns the underlying JavaScript type of any runtime value.
14+
15+
See [`typeof`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) on MDN.
16+
17+
## Examples
18+
```rescript
19+
Console.log(Type.typeof("Hello")) // Logs "string" to the console.
20+
21+
let someVariable = true
22+
23+
switch someVariable->Type.typeof {
24+
| #boolean => Console.log("This is a bool, yay!")
25+
| _ => Console.log("Oh, not a bool sadly...")
26+
}
27+
```
28+
*/
329
external typeof: 'a => t = "#typeof"
430

531
module Classify: {
32+
/***
33+
Classifies JavaScript runtime values.
34+
*/
35+
36+
/**
37+
An abstract type representing a JavaScript function.
38+
39+
See [`function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) on MDN.
40+
*/
641
type function
42+
43+
/**
44+
An abstract type representing a JavaScript object.
45+
46+
See [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) on MDN.
47+
*/
748
type object
49+
50+
/**
51+
An abstract type representing a JavaScript symbol.
52+
53+
See [`symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) on MDN.
54+
*/
855
type symbol
956

57+
/**
58+
The type representing a classified JavaScript value.
59+
*/
1060
type t =
1161
| Bool(bool)
1262
| Null
@@ -17,5 +67,17 @@ module Classify: {
1767
| Function(function)
1868
| Symbol(symbol)
1969

70+
/**
71+
`classify(anyValue)`
72+
Classifies a JavaScript value.
73+
74+
## Examples
75+
```rescript
76+
switch %raw(`null`)->Type.Classify.classify {
77+
| Null => Console.log("Yup, that's null.")
78+
| _ => Console.log("This doesn't actually appear to be null...")
79+
}
80+
```
81+
*/
2082
let classify: 'a => t
2183
}

0 commit comments

Comments
 (0)
Please sign in to comment.