Skip to content

Commit b7dd071

Browse files
Add example for omitting trailing undefineds
1 parent e0ba373 commit b7dd071

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

_blogposts/2024-02-01-release-11-1-0.mdx

+41
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,47 @@ let x = <custom-tag />
134134
135135
This is particularly useful when dealing with [web components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components), where element names tend to use hyphens.
136136
137+
## Omit trailing undefined in external function calls
138+
139+
ReScript 11's uncurried mode allows for much more ergonomic external function bindings, because trailing units were not needed anymore. But, this comes with a potential problem. All arguments, whether they're actually supplied or not, were printed as `undefined` in the resulting JS. This is handled better now, as trailing `undefined`s are automatically omitted.
140+
141+
<CodeTab labels={["ReScript", "JS Output (ReScript 11.0)", "JS Output (ReScript 11.1)"]}>
142+
143+
```res
144+
@val
145+
external stringify: (
146+
'a,
147+
~replacer: (string, JSON.t) => JSON.t=?,
148+
~space: int=?,
149+
) => string = "JSON.stringify"
150+
151+
let obj = {"test": 1}
152+
153+
let result = stringify(obj)
154+
155+
let result2 = stringify(obj, ~space=2)
156+
```
157+
```js
158+
var obj = {
159+
test: 1
160+
};
161+
162+
var result = JSON.stringify(obj, undefined, undefined);
163+
164+
var result2 = JSON.stringify(obj, undefined, 2);
165+
```
166+
```js
167+
var obj = {
168+
test: 1
169+
};
170+
171+
var result = JSON.stringify(obj);
172+
173+
var result2 = JSON.stringify(obj, undefined, 2);
174+
```
175+
</CodeTab>
176+
177+
137178
## Other changes
138179
139180
Of course we also got a bunch of other changes and bug fixes in this release. Check out the [compiler changelog](https://github.com/rescript-lang/rescript-compiler/blob/11.0_release/CHANGELOG.md#1110-rc1) if you are interested.

0 commit comments

Comments
 (0)