-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Make method arguments optional if possible" section has bad advice #437
Comments
I’d have imagined “converting” here referred to ES → Web IDL conversion, likewise type of the argument and boolean in their Web IDL senses. If that’s accurate, then it doesn’t follow that converting undefined to the type of the argument always aligns with outcomes like (I agree with the conclusion about this passage regardless, but figured it was worth pointing out that this reads pretty differently if |
Ah, that's probably correct. Looks like it works out the same in practice - converting |
Yep, but if the type were |
This section says
and I think that's basically wrong? A string-taking API should not be required to use the default value
"undefined"
, which is what you get when convertingundefined
to a string (unless this document is using "converting" in an unusual way, i.e. not just'' + undefined
). Similarly,NaN
is almost never the right default for a Number-taking API, and0
is only sometimes a reasonable default for an integer-taking API, which are what you get when convertingundefined
to a Number or integer in JS.Rather, the way I'd put it is that an explicit
undefined
should be treated exactly the same as an option being absent1. And, in addition,false
should be the default for boolean parameters. This doesn't tell you anything about the appropriate default for other type, though.(That rule appears to have been introducing in #228.)
Footnotes
except in the (very rare) cases where
undefined
is a coherent value to use - for example, in JS thecause
parameter in error constructors can take any JS value, includingundefined
, so that's one of the very rare cases which breaks this rule. ↩The text was updated successfully, but these errors were encountered: