From e53229bf91e73df4a1b5b6be3ef39b1737397b63 Mon Sep 17 00:00:00 2001 From: floy Date: Wed, 6 Nov 2024 09:20:23 +0100 Subject: [PATCH] Update README.md (#80) Add note about default option for `choices` --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9d5bc35..920110c 100644 --- a/README.md +++ b/README.md @@ -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 ').choices(['small', 'medium', 'large'] as const)) - .parse(); + .addOption( + new Option('--drink-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 ```