Skip to content

Add fixed arguments case to as decorator syntax lookup entry #1021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2025
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