Skip to content
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

Boolean default value coercion #301

Closed
Eomm opened this issue Aug 14, 2020 · 2 comments
Closed

Boolean default value coercion #301

Eomm opened this issue Aug 14, 2020 · 2 comments
Labels

Comments

@Eomm
Copy link
Contributor

Eomm commented Aug 14, 2020

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

@bcoe bcoe added the question label Sep 20, 2020
@bcoe
Copy link
Member

bcoe commented Sep 20, 2020

@Eomm try this:

default: { bool: false }

The defaults for a typed option, like a number, boolean, or string, should be of the same type as the option 👍

@Eomm
Copy link
Contributor Author

Eomm commented Sep 21, 2020

Thks, I read the linked issue and it seems the desidered behavior

Closing per duplicate of #143

@Eomm Eomm closed this as completed Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants