(no title)
mjlawson | 1 year ago
Using object arguments is a great start, and I think using enums can also be powerful (if you're using string literal types). But often times I reach for explicit interfaces in these situations. IE:
type FooScenario = { arg1: true; arg2: true; arg3: true };
type BarScenario = { arg1: false; arg2: true; arg3: false; }
type Scenario = FooScenario | BarScenario;
...etc
This provides semantic benefits in that it'll limit the input to the function (forcing callers to validate their input), and it also provides a scaffold to build useful, complete test cases.
No comments yet.