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

[yargs] Added strictOptions typing #48657

Merged
merged 1 commit into from Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions types/yargs/index.d.ts
Expand Up @@ -563,6 +563,14 @@ declare namespace yargs {
strict(): Argv<T>;
strict(enabled: boolean): Argv<T>;

/**
* Similar to `.strict()`, except that it only applies to unrecognized options. A
* user can still provide arbitrary positional options, but unknown options
* will raise an error.
*/
strictOptions(): Argv<T>;
strictOptions(enabled: boolean): Argv<T>;

/**
* Tell the parser logic not to interpret `key` as a number or boolean. This can be useful if you need to preserve leading zeros in an input.
*
Expand Down
11 changes: 11 additions & 0 deletions types/yargs/yargs-tests.ts
Expand Up @@ -1277,3 +1277,14 @@ function Argv$commandsWithAsynchronousBuilders() {
function makeSingleton() {
yargsSingleton(process.argv.slice(2));
}

function Argv$strictOptions() {
// test taken from https://github.com/yargs/yargs/blob/master/test/validation.cjs#L1036
const argv1 = yargs
.command('foo', 'foo command')
.option('a', {
describe: 'a is for option'
})
.strictOptions()
.argv;
}