-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Preset option type discrepancy #1973
Comments
This is as intended, albeit subtle. Preset was added in #1652. The tests in https://github.com/tj/commander.js/blob/master/tests/options.preset.test.js include tests for There are essentially two usage patterns. The first is setting a preset value without a custom parser, which is a successor to some previous use of The second usage pattern is to support calling custom argument parser on preset value. This is different than behaviour for |
Thanks for the clear explanation! I would then suggest to also use |
An answer was provided, and no further activity in a month. Closing this as resolved. Feel free to open a new issue if it comes up again, with new information and renewed interest. |
This results in:
The reason is that the
Option.preset()
parameter type is set tounknown
,commander.js/typings/index.d.ts
Line 118 in 4ef19fa
while the
parseArg
type is designed in such a way that only strings are expected in the first argument.commander.js/typings/index.d.ts
Line 97 in 4ef19fa
This is problematic because custom processing (
parseArg
) is called for preset option values.(The reason why the call in the library's source did not result in an error when running the type check that led to #1967 is that the
.preset()
parameter type isany
rather thanunknown
inlib/option.js
:commander.js/lib/option.js
Lines 62 to 66 in 4ef19fa
I suspect this discrepancy is due to an expectation that vanilla JSDoc supports
any
but notunknown
, but actually, there seems to be only one way to declare parameters that accept any arguments in vanilla JSDoc, and that is@param {*}
, sounknown
could be used here just as well.)But anyway. My suggestion is that we require that the argument to
Option.preset()
be a string. Or we change theparseArg
signature so that arbitrary values are accepted.The text was updated successfully, but these errors were encountered: