Skip to content

Use optional arguments in bindings #206

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

Closed
cknitt opened this issue Apr 1, 2024 · 2 comments
Closed

Use optional arguments in bindings #206

cknitt opened this issue Apr 1, 2024 · 2 comments
Assignees

Comments

@cknitt
Copy link
Member

cknitt commented Apr 1, 2024

Many JavaScript APIs have methods with trailing optional args and are currently bound in Core as multiple different functions for different argument counts.

However, since ReScript 11, we can have trailing optional args in functions/bindings without needing a () at the end anymore. This allows us to create more idiomatic bindings for such cases, corresponding more closely to the original JS API.

I have already created the following PRs for a some such cases:

There are quite a few other bindings left that should be changed in a similar way (e.g., Date.make).

For some such functions, the trailing undefineds emitted by the 11.0 compiler for the omitted arguments will be problematic and therefore ReScript 11.1 will be required.

@tsnobip
Copy link
Member

tsnobip commented Feb 11, 2025

@cknitt do you see any other APIs than Date.makeWith* for this issue?
The thing is we could not use optional parameters for this given this could create invalid dates (it would only work if missing parameters would be replaced with null instead of undefined).

There's one thing we could fix though, they use a ~date parameter instead of ~day, would you like me to correct this?

@tsnobip
Copy link
Member

tsnobip commented Mar 7, 2025

closing this unless we find other optional arguments for bindings.

@tsnobip tsnobip closed this as completed Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants