Skip to content

Existence of ‘number’ Key in Options.arrays Changes Parsing #415

Open

Description

@JoeDailey

The documentation says to set numbers: true to parse option-array values as numbers. However, this value can be anything other than true and yargs will still use number parsing. This is particularly confusing when trying to set numbers: false or numbers: undefined.

> const parser = require('yargs-parser')
undefined
> parser('--foo dog cat', {array: {key: 'foo'}})
{ _: [], foo: [ 'dog', 'cat' ] }
> parser('--foo dog cat', {array: {key: 'foo', number: false}})
{ _: [], foo: [ NaN, NaN ] }
> parser('--foo dog cat', {array: {key: 'foo', number: undefined}})
{ _: [], foo: [ NaN, NaN ] } 

This applies to boolean as well.

Activity

  1. bcoe commented on Oct 4, 2021

    @bcoe
    Member

    @JoeDailey thank you for bug report.

  2. shadowspawn commented on Oct 10, 2026

    @shadowspawn
    Member

    Thanks for the compact examples using the node REPL.

    I see how you were confused, but the intended way of preventing the automatic number conversion is to set string: true.

    In general terms, options may be boolean or string or number. Setting number: false is not enough to tell yargs-parser what you intend.

    yargs-parser could throw a configuration error, but this issue has not been upvoted in a few years and unlikely to change behaviour based on current information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions