Skip to content

Function arguments

In general we prefer to pass function arguments as a single object instead of multiple parameters

i.e. we prefer

interface AssignUserRequest {
userId: string;
authenticatorId: string;
}
const assignUser = (request: AssignUserRequest) => ...

over

const assignUser = (userId: string, authenticatorId: string) => ...

simply because it prevents us from doing something like this:

assignUser(authenticatorId, userId)
// its userId not username!
assignUser(username, authenticatorId)

The exception to this “rule” is when a function accepts one primitive argument along with some options:

interface ApiOptions {
tenancyId: string
}
type exchangeCode = (code: string, options: ApiOptions) => ...