File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,28 @@ let somethingElse = null;
82
82
83
83
Read more about the [ ` @as ` decorator and variants] ( variant.md#valid-as-payloads ) .
84
84
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
+
85
107
### References
86
108
87
109
* [ 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