Replies: 1 comment
-
The correct way is: function foo(
requiredArg1: string,
{
optionalArgument1 = "defaultValueForOptionalArgument1";
optionalArgument2 = "defaultValueForOptionalArgument2";
} = {},
): void {
console.log("requiredArg1", requiredArg1);
console.log("options.optionalArgument1", options.optionalArgument1);
console.log("options.optionalArgument2", options.optionalArgument2);
}; We should show an example in the style guide. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In the style guide docs an options object to place all optional parameters is regarded as good practice https://deno.land/[email protected]/contributing/style_guide#exported-functions-max-2-args-put-the-rest-into-an-options-object
The docs don't expand how one may go about using default values to these optional parameters.
Take the use case here
Calling this like
Gives this output
Even though I understand why the output is such it seems a very easy thing to miss and if I were to look over the code quickly I would expect the below
Taking this into account I was wondering if Deno developers still think the options pattern when used with default values is a good style. I know there are arguments for both for and against but I would like to hear your thoughts 😃
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions