Skip to content

Commit 5b7e803

Browse files
authored
Add type t to Stdlib modules (#7302)
* add a type t as an alias of the built-in types
1 parent d1c9aef commit 5b7e803

17 files changed

+60
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
- Allow single newline in JSX. https://github.com/rescript-lang/rescript/pull/7269
2222
- Editor: Always complete from Core first. Use actual native regex syntax in code snippets for regexps. https://github.com/rescript-lang/rescript/pull/7295
23+
- Add `type t` to Stdlib modules. https://github.com/rescript-lang/rescript/pull/7302
2324

2425
#### :bug: Bug fix
2526

runtime/Stdlib_Array.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
type t<'a> = array<'a>
12
type arrayLike<'a>
23

34
@new external makeUninitializedUnsafe: int => array<'a> = "Array"

runtime/Stdlib_Array.resi

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/***
2+
A mutable array.
3+
4+
Compiles to a regular JavaScript array.*/
5+
6+
/**
7+
Type representing an array of value `'a`.
8+
*/
9+
type t<'a> = array<'a>
10+
111
type arrayLike<'a>
212

313
/**

runtime/Stdlib_BigInt.res

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
Type representing a bigint.
3+
*/
4+
type t = bigint
5+
16
@val external asIntN: (~width: int, bigint) => bigint = "BigInt.asIntN"
27
@val external asUintN: (~width: int, bigint) => bigint = "BigInt.asUintN"
38

runtime/Stdlib_Float.res

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
type t = float
2+
13
module Constants = {
24
@val external nan: float = "NaN"
35
@val external epsilon: float = "Number.EPSILON"

runtime/Stdlib_Float.resi

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
Functions for interacting with float.
2727
*/
2828

29+
/**
30+
Type representing a float.
31+
*/
32+
type t = float
33+
2934
/**
3035
Float constants.
3136
*/

runtime/Stdlib_Int.res

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
type t = int
2+
13
module Constants = {
24
@inline let minValue = -2147483648
35
@inline let maxValue = 2147483647

runtime/Stdlib_Int.resi

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ Functions for interacting with JavaScript Number.
2727
See: [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number).
2828
*/
2929

30+
/**
31+
Type representing an int.
32+
*/
33+
type t = int
34+
3035
module Constants: {
3136
/**
3237
The smallest positive number represented in JavaScript.

runtime/Stdlib_List.res

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161

6262
@@config({flags: ["-bs-noassertfalse"]})
6363

64+
type t<'a> = list<'a>
65+
6466
module A = {
6567
@new external makeUninitializedUnsafe: int => array<'a> = "Array"
6668
external min: ('a, 'a) => 'a = "%bs_min"

runtime/Stdlib_List.resi

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ Collection functions for manipulating the `list` data structures, a singly-linke
3131
- Better interop with JavaScript
3232
- Better memory usage & performance.
3333
*/
34+
/**
35+
Type representing a list of value `'a`.
36+
*/
37+
type t<'a> = list<'a>
38+
3439
/**
3540
`length(list)` returns the length of `list`.
3641

runtime/Stdlib_Option.res

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* You should have received a copy of the GNU Lesser General Public License
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24+
type t<'a> = option<'a> = None | Some('a)
2425

2526
let filter = (opt, p) =>
2627
switch opt {

runtime/Stdlib_Option.resi

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ let someString: option<string> = Some("hello")
3939
```
4040
*/
4141

42+
/**
43+
Type representing an option of type 'a.
44+
*/
45+
type t<'a> = option<'a> = None | Some('a)
46+
4247
/**
4348
`filter(opt, f)` applies `f` to `opt`, if `f` returns `true`, then it returns `Some(value)`, otherwise returns `None`.
4449

runtime/Stdlib_Result.res

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* You should have received a copy of the GNU Lesser General Public License
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24+
type t<'res, 'err> = result<'res, 'err> = Ok('res) | Error('err)
2425

2526
let getExn = x =>
2627
switch x {

runtime/Stdlib_Result.resi

+6-1
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@
4545
}
4646
```
4747
*/
48+
type t<'res, 'err> = result<'res, 'err> = Ok('res) | Error('err)
49+
4850
/**
4951
`getExn(res)`: when `res` is `Ok(n)`, returns `n` when `res` is `Error(m)`, raise an exception
5052

5153
```res example
5254
Result.getExn(Result.Ok(42)) == 42
5355

54-
Result.getExn(Result.Error("Invalid data")) /* raises exception */
56+
switch Result.getExn(Error("Invalid data")) {
57+
| exception Not_found => assert(true)
58+
| _ => assert(false)
59+
}
5560
```
5661
*/
5762
let getExn: result<'a, 'b> => 'a

runtime/Stdlib_String.res

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
type t = string
2+
13
@val external make: 'a => string = "String"
24

35
@val external fromCharCode: int => string = "String.fromCharCode"

runtime/Stdlib_String.resi

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ Functions for interacting with JavaScript strings.
2727
See: [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String).
2828
*/
2929

30+
/**
31+
Type representing a string.
32+
*/
33+
type t = string
34+
3035
/**
3136
`make(value)` converts the given value to a `string`.
3237

tests/analysis_tests/tests/src/expected/Completion.res.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ Path this
19511951
"kind": 12,
19521952
"tags": [],
19531953
"detail": "\\\"Type Not Known\"",
1954-
"documentation": {"kind": "markdown", "value": "```rescript\ntype props<'first, 'zoo, 'second> = {\n first?: 'first,\n zoo?: 'zoo,\n second: 'second,\n}\n```"}
1954+
"documentation": null
19551955
}]
19561956

19571957
Hover src/Completion.res 349:14
@@ -2511,7 +2511,7 @@ Path Stdlib.Result.g
25112511
"kind": 12,
25122512
"tags": [],
25132513
"detail": "result<'a, 'b> => 'a",
2514-
"documentation": {"kind": "markdown", "value": "\n Result types are really useful to describe the result of a certain operation\n without relying on exceptions or `option` types.\n\n This module gives you useful utilities to create and combine `Result` data.\n"}
2514+
"documentation": {"kind": "markdown", "value": "\n `getExn(res)`: when `res` is `Ok(n)`, returns `n` when `res` is `Error(m)`, raise an exception\n\n ```res example\n Result.getExn(Result.Ok(42)) == 42\n\n switch Result.getExn(Error(\"Invalid data\")) {\n | exception Not_found => assert(true)\n | _ => assert(false)\n }\n ```\n"}
25152515
}, {
25162516
"label": "Result.getOr",
25172517
"kind": 12,

0 commit comments

Comments
 (0)