Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf7e3343

Browse files
Global docstrings (#7976)
* Add global docstrings* Completions* Fix* Simplify* Completions again* Add warning about rather writing own bindings
1 parent6cfac38 commitf7e3343

File tree

6 files changed

+69
-7
lines changed

6 files changed

+69
-7
lines changed

‎packages/@rescript/runtime/Stdlib.res‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ type lazy_t<+'a> = Lazy.t<'a>
6262

6363
@deprecated("Use rescript-webapi instead") @valexternalwindow:Dom.window="window"
6464
@deprecated("Use rescript-webapi instead") @valexternaldocument:Dom.document="document"
65+
/**
66+
`globalThis` gives you the host global object (`window` in browsers, `global` in Node, etc.).
67+
You can reach shared globals from any runtime without special checks.
68+
69+
## Examples
70+
71+
**Note:** These are demonstrative examples. In real code, prefer writing your own type-safe bindings.
72+
See [`Bind to Global JS Values`](https://rescript-lang.org/docs/manual/v12.0.0/bind-to-global-js-values).
73+
74+
75+
```rescript
76+
typeof(globalThis["setTimeout"]) == #function
77+
78+
globalThis["myAppName"] = "SuperApp";
79+
globalThis["myAppName"] == "SuperApp"
80+
```
81+
*/
6582
@valexternalglobalThis: {..}="globalThis"
6683

6784
/**
@@ -106,6 +123,20 @@ async function main() {
106123
*/
107124
externalimport:'a=>promise<'a>="%import"
108125

126+
/**
127+
`panic(message)` throws a JavaScript `Error` prefixed with `Panic!`.
128+
Call it when something went wrong and the program should stop right away.
129+
130+
## Examples
131+
132+
```rescript
133+
let caught = try panic("Invariant violated") catch {
134+
| JsExn(err) => JsExn.message(err)->Option.getOrThrow
135+
}
136+
137+
caught == "Panic! Invariant violated"
138+
```
139+
*/
109140
letpanic=JsError.panic
110141

111142
/**
@@ -123,6 +154,37 @@ let assertEqual = (a, b) => {
123154
}
124155
}
125156

157+
/**
158+
`null` returns the JavaScript `null` value as a `nullable<'a>`.
159+
Use the `Nullable` helpers to convert it into an `option` or to read the value.
160+
161+
## Examples
162+
163+
```rescript
164+
null->Nullable.toOption == None
165+
```
166+
*/
126167
externalnull:nullable<'a>="#null"
168+
/**
169+
`undefined` returns the JavaScript `undefined` value as a `nullable<'a>`.
170+
Use the `Nullable` helpers to convert it into an `option` or to read the value.
171+
172+
## Examples
173+
174+
```rescript
175+
undefined->Nullable.toOption == None
176+
```
177+
*/
127178
externalundefined:nullable<'a>="#undefined"
179+
/**
180+
`typeof(value)` exposes JavaScript's `typeof` operator and returns a `Type.t` enum.
181+
It helps you inspect values that come from JavaScript APIs.
182+
183+
## Examples
184+
185+
```rescript
186+
typeof(1) == #number
187+
typeof("a") == #string
188+
```
189+
*/
128190
externaltypeof:'a=>Type.t="#typeof"

‎packages/@rescript/runtime/lib/es6/Stdlib.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertEqual(a, b) {
1212
RE_EXN_ID:"Assert_failure",
1313
_1:[
1414
"Stdlib.res",
15-
122,
15+
153,
1616
4
1717
],
1818
Error:newError()

‎packages/@rescript/runtime/lib/js/Stdlib.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertEqual(a, b) {
1212
RE_EXN_ID:"Assert_failure",
1313
_1:[
1414
"Stdlib.res",
15-
122,
15+
153,
1616
4
1717
],
1818
Error:newError()

‎tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ Path fnTakingRecord
374374
"kind": 12,
375375
"tags": [],
376376
"detail": "'a => Type.t",
377-
"documentation":null
377+
"documentation":{"kind": "markdown", "value": "\n`typeof(value)` exposes JavaScript's `typeof` operator and returns a `Type.t` enum.\nIt helps you inspect values that come from JavaScript APIs.\n\n## Examples\n\n```rescript\ntypeof(1) == #number\ntypeof(\"a\") == #string\n```\n"}
378378
}]
379379

380380
Complete src/CompletionExpressions.res 69:25

‎tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Path someFn
4848
"kind": 12,
4949
"tags": [],
5050
"detail": "'a => Type.t",
51-
"documentation":null
51+
"documentation":{"kind": "markdown", "value": "\n`typeof(value)` exposes JavaScript's `typeof` operator and returns a `Type.t` enum.\nIt helps you inspect values that come from JavaScript APIs.\n\n## Examples\n\n```rescript\ntypeof(1) == #number\ntypeof(\"a\") == #string\n```\n"}
5252
}]
5353

5454
Complete src/CompletionFunctionArguments.res 16:25
@@ -372,7 +372,7 @@ Path someOtherFn
372372
"kind": 12,
373373
"tags": [],
374374
"detail": "'a => Type.t",
375-
"documentation":null
375+
"documentation":{"kind": "markdown", "value": "\n`typeof(value)` exposes JavaScript's `typeof` operator and returns a `Type.t` enum.\nIt helps you inspect values that come from JavaScript APIs.\n\n## Examples\n\n```rescript\ntypeof(1) == #number\ntypeof(\"a\") == #string\n```\n"}
376376
}]
377377

378378
Complete src/CompletionFunctionArguments.res 76:25

‎tests/analysis_tests/tests/src/expected/CompletionJsxProps.res.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Path CompletionSupport.TestComponent.make
4040
"kind": 12,
4141
"tags": [],
4242
"detail": "'a => Type.t",
43-
"documentation":null
43+
"documentation":{"kind": "markdown", "value": "\n`typeof(value)` exposes JavaScript's `typeof` operator and returns a `Type.t` enum.\nIt helps you inspect values that come from JavaScript APIs.\n\n## Examples\n\n```rescript\ntypeof(1) == #number\ntypeof(\"a\") == #string\n```\n"}
4444
}]
4545

4646
Complete src/CompletionJsxProps.res 6:50
@@ -378,7 +378,7 @@ Path CompletionSupport.TestComponent.make
378378
"kind": 12,
379379
"tags": [],
380380
"detail": "'a => Type.t",
381-
"documentation":null
381+
"documentation":{"kind": "markdown", "value": "\n`typeof(value)` exposes JavaScript's `typeof` operator and returns a `Type.t` enum.\nIt helps you inspect values that come from JavaScript APIs.\n\n## Examples\n\n```rescript\ntypeof(1) == #number\ntypeof(\"a\") == #string\n```\n"}
382382
}]
383383

384384
Complete src/CompletionJsxProps.res 44:44

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp