Skip to content

Commit

Permalink
Update README.md (#80)
Browse files Browse the repository at this point in the history
Add note about default option for `choices`
  • Loading branch information
leftshift authored Nov 6, 2024
1 parent 143c21f commit e53229b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ Use a "const assertion" on the choices to narrow the option type from `string`:

```typescript
const program = new Command()
.addOption(new Option('--drink-size <size>').choices(['small', 'medium', 'large'] as const))
.parse();
.addOption(
new Option('--drink-size <size>')
.choices(['small', 'medium', 'large'] as const)
// if you want to provide a default option, also add a const assertion to it
.default('medium' as const)
).parse();
const drinkSize = program.opts().drinkSize; // "small" | "medium" | "large" | undefined
```

0 comments on commit e53229b

Please sign in to comment.