Helpers
Function-based helpers
type FunctionBasedHelper =
(positional: unknown[], named: Record<string, unknown>) => string | void;Handling positional arguments
positional argumentsfunction totalLength(positional: unknown[]) {
// Account for case where user passes no arguments
assert(
'all positional args to `total-length` must be strings',
positional.every(arg => typeof arg === 'string')
);
// safety: we can cast `positional as string[]` because we asserted above
return (positional as string[]).reduce((sum, s) => sum + s.length, 0);
}Handling named arguments
named argumentspositional and named presence
positional and named presencePutting it all together
Class-based helpers
Last updated
Was this helpful?