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

Allow readonly arrays to be used as choices #1679

Closed
wants to merge 1 commit into from
Closed

Commits on Jan 16, 2022

  1. Allow readonly arrays to be used as choices

    Consider following usage:
    
    ```ts
    const SupportedDrinks = ['small', 'medium', 'large'] as const;
    type Drink = typeof SupportedDrinks[number];
    
    const program = new Command()
          .addOption(new Option('-d, --drink <size>', 'drink size').choices(SupportedDrinks))
    ```
    
    This allows user to get a strongly typed enum and reuse it to automatically populate supported drinks. 
    This code doesn't compile now though since readonly array is not assignable to just `string[]`.
    Pzixel committed Jan 16, 2022
    Configuration menu
    Copy the full SHA
    7bbee8d View commit details
    Browse the repository at this point in the history