[RFC] Object parameters for javascript target
Once #24 is done and we can use npm for versioning, breaking changes will become less scary. With that out of the way, I propose we implement an opt-in (maybe as a plugin?) object mode for endpoints' arguments, as follows:
// object mode disabled
function logIn(username: string, password: string) { /* stuff */ }
// object mode enabled
function logIn(args: { username: string, password: string }) { /* stuff */ }
By doing so, breaking changes can be more easily detected and fixed: imagine the logIn function changes, so that it starts to receive a username and a token, both strings. Without object mode, the change wouldn't be detected by type systems (as password and token have the same type), introducing subtle bugs.
Another kind of bug easily introduced without object mode but avoided with it, is based on the fact that arguments order matter: switching arguments of the same type (e.g. logIn(password, username)) is easily done and hardly detectable.
Any thoughts?
With proper versioning maybe we can not offer option at all and implement the breaking change. Upgrading will be optional, so the old style can be phased away easily.
Are there situations where it would be preferable to use the current style (no object)?
None that I can think of. If it's agreed, I'm all in for it as the default signature.