Commit 8ca3c3d
committed
Add string[] to options defaultValue type
option and requiredOption's defaultValue parameter was `string |
boolean` but the default for a variadic option should be an array.
```
program.option('--var <args...>', 'variadic arguments', ['1'])
program.parse([])
> { var: ['1'] }
program.parse(['--var', '1', '2'])
> { var: ['1', '2'] }
```
If you use a string default you have to handle opts that are strings
```
// with a string arg the default value is a string.
program.option('--var <args...>', 'variadic arguments', '1')
program.parse([])
> { var: '1' }
program.parse(['--var', '1', '2'])
> { var: ['1', '2'] }
```
`unknown` matches the jsdoc comment and the typings for argument(name:
string, description?: string, defaultValue?: unknown): this` but
conflicts with other `option` overloads.
commander will pass thru any defaultValue to parse opts so `any` or
`unknown` are good choices, but `string | boolean | string[]` reflects
the values that commander will return when it parses arguments without a
coerce function.1 parent a80b984 commit 8ca3c3d
1 file changed
+4
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
526 | | - | |
| 526 | + | |
527 | 527 | | |
528 | 528 | | |
529 | | - | |
| 529 | + | |
530 | 530 | | |
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
537 | | - | |
| 537 | + | |
538 | 538 | | |
539 | 539 | | |
540 | | - | |
| 540 | + | |
541 | 541 | | |
542 | 542 | | |
543 | 543 | | |
| |||
0 commit comments