-
Notifications
You must be signed in to change notification settings - Fork 994
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
[bug] command option's choises is of type unknown #2397
Comments
I was not able to reproduce this problem. I created a new package and initialised the TypeScript configuration with import yargsFactory from 'yargs/yargs';
const argv = yargsFactory(process.argv.slice(2))
.command('example', '...', {
test:{
choices: ["a", "b"] as const
}
})
.parseSync();
console.log(argv); % node ts.js example --test
ts.js example
...
Options:
--help Show help [boolean]
--version Show version number [boolean]
--test [choices: "a", "b"]
Invalid values:
Argument: test, Given: true, Choices: "a", "b" |
this is not the issue, yargs itself can detect the user's input. To reproduce the issue: |
(I misunderstood the issue. Thanks for explaining. I will have another look.) |
Here is a way of defining the command that gets the choices into the types. import yargsFactory from 'yargs/yargs';
const yargs = yargsFactory(process.argv.slice(2))
.command('example [test]', '...',
(yargs) => {
return yargs.positional('test', {
type: 'string',
choices: ["a", "b"] as const
});
},
(argv) => {
console.log(argv);
const inspect = argv.test; // <-- "a" | "b" | undefined
});
yargs.parseSync(); |
The text was updated successfully, but these errors were encountered: