xero-node
xero-node copied to clipboard
Consider changing from having 100 function parameters to an object
SDK you're using (please complete the following information):
- Version 4.27.0
Is your feature request related to a problem? Please describe.
A lot of the API methods have an insanely long list of parameters.
Here's one in my code: xero.projectApi.getTimeEntries(tenantId, projectId, userId, undefined, undefined, undefined, 1, 450, undefined, undefined, afterDate, beforeDate)
I don't think you can tell me this is ok :)
I feel wary upgrading to new versions as the order of these params may change, and depending on the types it may slip through without a compile error.
Describe the solution you'd like It's a very large breaking change, though overloading may potentially be possible....
Just use an object. It's much more obvious what is happening, and additional parameters can be added easily without errors.
xero.projectApi.getTimeEntries({
tenantId,
projectId,
userId,
page: 1,
pageSize: 450,
dateAfterUtc: afterDate,
dateBeforeUtc: beforeDate
});
tenantId could be separate from the object. Additionally, you could split the options into two parts, url parameters (in this case, projectId) and the POST body.
Describe alternatives you've considered Some IDEs such as VS Code have a feature called "inlay hints" that write the parameter name directly inline in the call. This would solve the readability problem, but updates still would be error prone...
I like this idea but as you point out it's a large breaking change. We'll place this on hold with plans to explore implementing with the next breaking change
Hi @adamburgess, just wanted to let you know we're looking into this now. But as Rett said, we'll be implementing this with the next breaking change.