Skip to content

Commit 3ef9996

Browse files
authored
Add @ignore docs (#441)
1 parent 3d3d239 commit 3ef9996

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

misc_docs/syntax/decorator_ignore.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
id: "ignore-decorator"
3+
keywords: ["ignore", "decorator"]
4+
name: "@ignore"
5+
summary: "This is the `@ignore` decorator."
6+
category: "decorators"
7+
---
8+
9+
The `@ignore` decorator "hides" a parameter of an `external` function on the JS side. It's useful give a function call more type context without impacting the resulting JS.
10+
11+
12+
<CodeTab labels={["ReScript", "JS Output"]}>
13+
14+
```res
15+
@val external doSomething: (@ignore 'a, 'a) => unit = "doSomething"
16+
17+
doSomething("this only shows up in ReScript code", "test")
18+
```
19+
20+
```js
21+
doSomething("test");
22+
```
23+
24+
</CodeTab>
25+
26+
### References
27+
28+
* [Bind to JS Function (Ignore Arguments)](/docs/manual/latest/bind-to-js-function#ignore-arguments)

pages/docs/manual/latest/bind-to-js-function.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,27 @@ process.on("exit", function (exitCode) {
310310

311311
The `@as("exit")` and the placeholder `_` argument together indicates that you want the first argument to compile to the string `"exit"`. You can also use any JSON literal with `as`: `` @as(json`true`) ``, `` @as(json`{"name": "John"}`) ``, etc.
312312

313+
## Ignore arguments
314+
315+
You can also explicitly "hide" `external` function parameters in the JS output, which may be useful if you want to add type constraints to other parameters without impacting the JS side:
316+
317+
<CodeTab labels={["ReScript", "JS Output"]}>
318+
319+
```res
320+
@val external doSomething: (@ignore 'a, 'a) => unit = "doSomething"
321+
322+
doSomething("this only shows up in ReScript code", "test")
323+
```
324+
325+
```js
326+
doSomething("test");
327+
```
328+
329+
</CodeTab>
330+
331+
**Note:** It's a pretty niche feature, mostly used to map to polymorphic JS APIs.
332+
333+
313334
## Curry & Uncurry
314335

315336
Curry is a delicious Indian dish. More importantly, in the context of ReScript (and functional programming in general), currying means that function taking multiple arguments can be applied a few arguments at time, until all the arguments are applied.

0 commit comments

Comments
 (0)