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

"Coerce" calls always on option, does it correct behaviour? #2158

Closed
lis355 opened this issue Apr 3, 2022 · 5 comments
Closed

"Coerce" calls always on option, does it correct behaviour? #2158

lis355 opened this issue Apr 3, 2022 · 5 comments
Assignees

Comments

@lis355
Copy link

lis355 commented Apr 3, 2022

Run this simple script WITHOUT any cli arguments:

const path = require("path");

const yargs = require("yargs/yargs");

const argv = yargs(process.argv.slice(2))
	.option("someArg", {
		type: "string",
		coerce: path.resolve
	})
	.parse();

You will get error message in output:

[C:\Program]() Files\nodejs\node.exe [.\main.js]()
Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
  --someArg                                                             [string]
node_modules/yargs/build/index.cjs:1
The "path" argument must be of type string. Received undefined
node_modules/yargs/build/index.cjs:1
Process exited with code 1

Does it correct? If my someArg is not a demand, why he "gets" default value undefined and then coerce is called? And, of cource, path.resolve drop this error

I think, it's not correct, to call coerce, if user not give an argument

@xmedeko
Copy link

xmedeko commented Apr 5, 2022

Seems like duplicate of #2130

@lis355
Copy link
Author

lis355 commented Apr 5, 2022

@xmedeko Yeah, thanks

@xmedeko
Copy link

xmedeko commented Apr 5, 2022

@lis355 If you agree it's a duplicate, then close the issue...

@jly36963 jly36963 self-assigned this Apr 6, 2022
@xmedeko
Copy link

xmedeko commented Apr 20, 2022

Should be fixed in 17.4.1.

@lis355
Copy link
Author

lis355 commented Apr 27, 2022

Thanks!

Close because duplicate of #2130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants