Skip to content

Commit 17d9df3

Browse files
committed
add fixed arguments case to as decorator syntax lookup entry
1 parent cdf968b commit 17d9df3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

misc_docs/syntax/decorator_as.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,28 @@ let somethingElse = null;
8282

8383
Read more about the [`@as` decorator and variants](variant.md#valid-as-payloads).
8484

85+
## Adding fixed argument values to external functions
86+
You can leverage the `@as` decorator to add fixed values for external function arguments. You then do not need to supply a value for that argument.
87+
88+
<CodeTab labels={["ReScript", "JS Output"]}>
89+
90+
```res
91+
@module("fs")
92+
external readFileSyncUtf8: (string, @as(json`{encoding: "utf8"}`) _) => string = "readFileSync"
93+
94+
let contents = readFileSyncUtf8("./someFile.txt")
95+
```
96+
97+
```js
98+
import * as Fs from "fs";
99+
100+
let contents = Fs.readFileSync("./someFile.txt", {encoding: "utf8"});
101+
```
102+
103+
</CodeTab>
104+
105+
Read more about [fixed arguments in functions](bind-to-js-function.md#fixed-arguments).
106+
85107
### References
86108

87109
* [Bind Using ReScript Record](/docs/manual/latest/bind-to-js-object#bind-using-rescript-record)

0 commit comments

Comments
 (0)