File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,28 @@ let somethingElse = null;
8282
8383Read 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 )
You can’t perform that action at this time.
0 commit comments