Hacker News new | ask | show | jobs
by carlos-menezes 426 days ago
Likewise. Even if the input object only has a single property, I'll still use this pattern.
2 comments

Another common pattern is to put the "primary" argument first, and the rest in an "options" object argument.
It works fine when your function takes a single primary argument—like `getLastWord(word: string, options?: TGetLastWordOptions): string | undefined`. The function name makes the purpose clear, and with just one main argument, it’s easy to follow. Sure, you're still "guessing" what the first parameter is but it’s not a heavy mental lift. You could argue that as long as you're consistent, using positional arguments in binary functions is fine–the pattern is clear and predictable.

But in the example from the OP, there isn’t really a primary argument. You're dealing with multiple values that carry equal weight, which makes positional arguments harder to reason about at a glance.

because i'm likely going to refactor this function "tomorrow" with additional properties. :)