Skip to content

Boolean default value coercion #301

Closed
@Eomm

Description

@Eomm

I didn't found another issue about this example:
when a boolean has a default value that is not a boolean, the type is not coerced from v14 to the last one.

Is this the intended behaviour or could it be a bug?

var yargsParser = require("yargs-parser")

yargsParser(['--use-default'], {
    boolean: ['bool'],
    default: { bool: 'false' }
})

// v13 output:
// Object {_: [], bool: false, use-default: true, useDefault: true}

// from v14 output:
// Object {_: [], bool: "false", use-default: true, useDefault: true}
// if I set "42"
// Object {_: [], bool: 42, use-default: true, useDefault: true}

https://runkit.com/embed/bbdymbdxa7bc


The use case is storing some defaults value in the process.env that are plain string and injecting them as default

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