I’m building a small library that exposes a function:
await printLib({optionsObj})
Currently, the options parameter is an object with different (optional) properties.
A?: <boolean>
B?: <boolean>
C?: <boolean>
Users can pass either true or false to any option. BUT A and B cannot be both true, or else an error is thrown.
In my case, although A and B cannot be true at the same time, B and C can have the same boolean values.
How to place my arguments so that users have an intuitive sense of which options can go together and which can’t?
Does it call for a redesign of the function?
One solution is to take string
values as the parameter: "A" | "B" | "C"
. However, this should be applied when all the possible options (A,B,C) are mutually exclusive – either A or B or C.
Zin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.