Skip to content
Merged
Changes from all 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
22 changes: 22 additions & 0 deletions misc_docs/syntax/decorator_as.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ let somethingElse = null;

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

## Adding fixed argument values to external functions
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.

<CodeTab labels={["ReScript", "JS Output"]}>

```res
@module("fs")
external readFileSyncUtf8: (string, @as(json`{encoding: "utf8"}`) _) => string = "readFileSync"

let contents = readFileSyncUtf8("./someFile.txt")
```

```js
import * as Fs from "fs";

let contents = Fs.readFileSync("./someFile.txt", {encoding: "utf8"});
```

</CodeTab>

Read more about [fixed arguments in functions](bind-to-js-function.md#fixed-arguments).

### References

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