Define exported helpers with const and an arrow function (or const + function expression) rather than a function declaration. Keeps style consistent and avoids hoisting surprises.
Good
export const parseArray = (
str: string,
options?: { separator?: string }
): string[] => {
// ...
};Avoid
export function parseArray(
str: string,
options?: { separator?: string }
): string[] {
// ...
}For helpers that accept configuration beyond the primary input (or where more knobs may be added later), use a single options object as the last argument instead of extra positional parameters.
- Defaults belong on that object (e.g.
separatordefaulting to","). - Document option keys in JSDoc on the
optionsparameter or per-field.
Good
export const parseArray = (
str: string,
options?: { separator?: string }
): string[] => {
const { separator = "," } = options ?? {};
// ...
};Avoid (positional config — harder to extend and to call with partial overrides)
export const parseArray = (str: string, separator = ","): string[] => {
// ...
};The primary value (str, id, etc.) stays the first argument; everything else goes in options.