Description
https://rescript-lang.org/docs/manual/latest/function#optional-labeled-arguments
There are a couple of things about optional args that are not coder-friendly:
- Positional args cannot be optional (even if there is just one arg)
- The need for "unit" param/arg as a final positional arg even when all args are labelled
Is there no way to make this a nicer experience? Mixing positional and labelled args in general seems a slightly odd allowance, but particularly so if it is causing this "unit" oddness. A necomer to the language (e.g. me a couple of weeks ago) is not going to understand why this is necessary:
Note for the sake of the type system, whenever you have an optional argument, you need to ensure that there's also at least one positional argument (aka non-labeled, non-optional argument) after it. If there's none, provide a dummy unit (aka ()) argument.
The need for "a dummy unit argument" is precisely the kind of quirk that could turn people away from this language. We come here in search of something better than typescript, so if this is going to remain in the language, I think we deserve a more detailed explanation than "for the sake of the type system". What is the trade-off here, what are we gaining in exchange for needing to use the dummy unit arg?