Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions packages/@rescript/runtime/Stdlib.res
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ type lazy_t<+'a> = Lazy.t<'a>

@deprecated("Use rescript-webapi instead") @val external window: Dom.window = "window"
@deprecated("Use rescript-webapi instead") @val external document: Dom.document = "document"
/**
`globalThis` gives you the host global object (`window` in browsers, `global` in Node, etc.).
You can reach shared globals from any runtime without special checks.

## Examples

```rescript
typeof(globalThis["setTimeout"]) == #function

globalThis["myAppName"] = "SuperApp";
globalThis["myAppName"] == "SuperApp"
```
*/
@val external globalThis: {..} = "globalThis"

/**
Expand Down Expand Up @@ -106,6 +119,20 @@ async function main() {
*/
external import: 'a => promise<'a> = "%import"

/**
`panic(message)` throws a JavaScript `Error` prefixed with `Panic!`.
Call it when something went wrong and the program should stop right away.

## Examples

```rescript
let caught = try panic("Invariant violated") catch {
| JsExn(err) => JsExn.message(err)->Option.getOrThrow
}

caught == "Panic! Invariant violated"
```
*/
let panic = JsError.panic

/**
Expand All @@ -123,6 +150,37 @@ let assertEqual = (a, b) => {
}
}

/**
`null` returns the JavaScript `null` value as a `nullable<'a>`.
Use the `Nullable` helpers to convert it into an `option` or to read the value.

## Examples

```rescript
null->Nullable.toOption == None
```
*/
external null: nullable<'a> = "#null"
/**
`undefined` returns the JavaScript `undefined` value as a `nullable<'a>`.
Use the `Nullable` helpers to convert it into an `option` or to read the value.

## Examples

```rescript
undefined->Nullable.toOption == None
```
*/
external undefined: nullable<'a> = "#undefined"
/**
`typeof(value)` exposes JavaScript's `typeof` operator and returns a `Type.t` enum.
It helps you inspect values that come from JavaScript APIs.

## Examples

```rescript
typeof(1) == #number
typeof("a") == #string
```
*/
external typeof: 'a => Type.t = "#typeof"
2 changes: 1 addition & 1 deletion packages/@rescript/runtime/lib/es6/Stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function assertEqual(a, b) {
RE_EXN_ID: "Assert_failure",
_1: [
"Stdlib.res",
122,
149,
4
],
Error: new Error()
Expand Down
2 changes: 1 addition & 1 deletion packages/@rescript/runtime/lib/js/Stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function assertEqual(a, b) {
RE_EXN_ID: "Assert_failure",
_1: [
"Stdlib.res",
122,
149,
4
],
Error: new Error()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ Path fnTakingRecord
"kind": 12,
"tags": [],
"detail": "'a => Type.t",
"documentation": null
"documentation": {"kind": "markdown", "value": "\n`typeof(value)` exposes JavaScript's `typeof` operator and returns a `Type.t` enum.\nUseful when narrowing values from dynamic sources.\n\n## Examples\n\n```rescript\ntypeof(1) == #number\ntypeof(\"a\") == #string\n```\n"}
}]

Complete src/CompletionExpressions.res 69:25
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Path someFn
"kind": 12,
"tags": [],
"detail": "'a => Type.t",
"documentation": null
"documentation": {"kind": "markdown", "value": "\n`typeof(value)` exposes JavaScript's `typeof` operator and returns a `Type.t` enum.\nUseful when narrowing values from dynamic sources.\n\n## Examples\n\n```rescript\ntypeof(1) == #number\ntypeof(\"a\") == #string\n```\n"}
}]

Complete src/CompletionFunctionArguments.res 16:25
Expand Down Expand Up @@ -372,7 +372,7 @@ Path someOtherFn
"kind": 12,
"tags": [],
"detail": "'a => Type.t",
"documentation": null
"documentation": {"kind": "markdown", "value": "\n`typeof(value)` exposes JavaScript's `typeof` operator and returns a `Type.t` enum.\nUseful when narrowing values from dynamic sources.\n\n## Examples\n\n```rescript\ntypeof(1) == #number\ntypeof(\"a\") == #string\n```\n"}
}]

Complete src/CompletionFunctionArguments.res 76:25
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Path CompletionSupport.TestComponent.make
"kind": 12,
"tags": [],
"detail": "'a => Type.t",
"documentation": null
"documentation": {"kind": "markdown", "value": "\n`typeof(value)` exposes JavaScript's `typeof` operator and returns a `Type.t` enum.\nUseful when narrowing values from dynamic sources.\n\n## Examples\n\n```rescript\ntypeof(1) == #number\ntypeof(\"a\") == #string\n```\n"}
}]

Complete src/CompletionJsxProps.res 6:50
Expand Down Expand Up @@ -378,7 +378,7 @@ Path CompletionSupport.TestComponent.make
"kind": 12,
"tags": [],
"detail": "'a => Type.t",
"documentation": null
"documentation": {"kind": "markdown", "value": "\n`typeof(value)` exposes JavaScript's `typeof` operator and returns a `Type.t` enum.\nUseful when narrowing values from dynamic sources.\n\n## Examples\n\n```rescript\ntypeof(1) == #number\ntypeof(\"a\") == #string\n```\n"}
}]

Complete src/CompletionJsxProps.res 44:44
Expand Down
Loading