diff --git a/types/yargs/index.d.ts b/types/yargs/index.d.ts index 92e344e05a..b14d4fb587 100644 --- a/types/yargs/index.d.ts +++ b/types/yargs/index.d.ts @@ -753,7 +753,7 @@ declare namespace yargs { type AsyncCompletionFunction = (current: string, argv: any, done: (completion: ReadonlyArray) => void) => void; type PromiseCompletionFunction = (current: string, argv: any) => Promise; type MiddlewareFunction = (args: Arguments) => void; - type Choices = ReadonlyArray; + type Choices = ReadonlyArray; type PositionalOptionsType = "boolean" | "number" | "string"; } diff --git a/types/yargs/yargs-tests.ts b/types/yargs/yargs-tests.ts index 87fb7fd16e..4808ef0979 100644 --- a/types/yargs/yargs-tests.ts +++ b/types/yargs/yargs-tests.ts @@ -817,6 +817,9 @@ function Argv$scriptName() { type Color = "red" | "blue" | "green"; const colors: ReadonlyArray = ["red", "blue", "green"]; +type Stage = 1 | 2 | 3 | 4; +const stages: ReadonlyArray = [1, 2, 3, 4]; + function Argv$inferOptionTypes() { // $ExpectType { [x: string]: unknown; a: (string | number)[] | undefined; b: boolean | undefined; c: number; n: number | undefined; s: string | undefined; _: string[]; $0: string; } yargs @@ -842,9 +845,10 @@ function Argv$inferOptionTypes() { .option("s", { string: true }) .argv; - // $ExpectType { [x: string]: unknown; choices: Color; coerce: Date | undefined; count: number; normalize: string | undefined; _: string[]; $0: string; } + // $ExpectType { [x: string]: unknown; choices: Color; numberChoices: Stage; coerce: Date | undefined; count: number; normalize: string | undefined; _: string[]; $0: string; } yargs .option("choices", { choices: colors, required: true }) + .option("numberChoices", { choices: stages, demandOption: true }) .option("coerce", { coerce: () => new Date() }) .option("count", { count: true }) .option("normalize", { normalize: true }) @@ -859,6 +863,9 @@ function Argv$inferOptionTypes() { // $ExpectType "red" | "blue" | "green" | undefined yargs.choices("x", colors).argv.x; + // $ExpectType number | undefined + yargs.choices('x', [1, 2, 3, 4]).argv.x; + // $ExpectType number | undefined yargs.coerce("x", Date.parse).argv.x;