frankframework / frontend-conventions

1 stars 0 forks source link

Options object pattern for Methods with a lot of Parameters #9

Closed philipsens closed 4 days ago

philipsens commented 2 weeks ago

Explanation (JS): https://www.codereadability.com/what-are-javascript-options-objects/ Article (TS): https://medium.com/@bchadwickfrance/the-options-object-pattern-with-typescript-a14f33306ec8

mhdirkse commented 2 weeks ago

Goed idee!

Matthbo commented 2 weeks ago

At what point / amount of parameters would you say its better to switch to an object parameter? I'm thinking of starting it at 3 or 4, I'm pretty sure most functions use about 1-2 parameters unless a function is very state dependent.

philipsens commented 2 weeks ago
method(options: {option1: string }): void {
// example
}

method(options: methodOptions): void {
// example
}
philipsens commented 2 weeks ago

This should be done with 3 or more parameters

Edit:

We chose to convert from 4

philipsens commented 2 weeks ago

This means that you could also have options as second parameter. When transforming an object it could be nice to have:

compare(object, object, {option: true})
philipsens commented 4 days ago

Add max param rule to eslint config