Skip to content

default on arrays do not behave as expected #2443

@kaizencc

Description

@kaizencc

Given the following option on a command:

.option('my-option', {
          type: 'array',
          desc: "my-desc",
        })

When my-option is not provided via the arguments, command['my-option'] is undefined, as expected.

But when I specify the option this way:

.option('my-option', {
          default: undefined,
          type: 'array',
          desc: "my-desc",
        })

I expect the default value for my-option to be undefined. However I see that the default value becomes [undefined]. This feels out of the ordinary and causes downstream issues when I try to ensure that my-option is undefined.

I would like yargs to respect my provided default and not throw it into an array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions