Skip to content

Commit

Permalink
chore(docs): remove unused type and inline the inference (#2086)
Browse files Browse the repository at this point in the history
  • Loading branch information
basarat committed Dec 21, 2021
1 parent 0d65c6c commit 10954f9
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions docs/typescript.md
Expand Up @@ -123,16 +123,13 @@ interface Arguments {

# More specific typing for choices()

To improve the `choices` option typing you can also specify its types:
To improve the `choices` option typing you can also specify it as const:

```typescript
const difficulties = ["normal", "nightmare", "hell"] as const;
type Difficulty = typeof difficulties[number];

const argv = yargs.option('difficulty', {
choices: difficulties,
choices: ["normal", "nightmare", "hell"] as const,
demandOption: true
}).argv;
```

`argv` will get type `'normal' | 'nightmare' | 'hell'`.
`argv.difficulty` will get type `'normal' | 'nightmare' | 'hell'`.

0 comments on commit 10954f9

Please sign in to comment.