[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

Support booleans and numbers in select values (#49)

authored by

Nate Moore and committed by
GitHub
(Feb 16, 2023, 8:45 AM -0600) e1053245 fe777cc0

+13 -7
+5
.changeset/bright-eagles-happen.md
··· 1 + --- 2 + "@clack/prompts": minor 3 + --- 4 + 5 + Improve types for select/multiselect prompts. Numbers and booleans are now supported as the `value` option.
+8 -7
packages/prompts/src/index.ts
··· 105 105 }).prompt() as Promise<boolean | symbol>; 106 106 }; 107 107 108 - interface Option<Value extends Readonly<string>> { 108 + type Primitive = Readonly<string | boolean | number>; 109 + interface Option<Value extends Primitive> { 109 110 value: Value; 110 111 label?: string; 111 112 hint?: string; 112 113 } 113 - export interface SelectOptions<Options extends Option<Value>[], Value extends Readonly<string>> { 114 + export interface SelectOptions<Options extends Option<Value>[], Value extends Primitive> { 114 115 message: string; 115 116 options: Options; 116 117 initialValue?: Options[number]["value"]; 117 118 } 118 119 119 - export interface MultiSelectOptions<Options extends Option<Value>[], Value extends Readonly<string>> { 120 + export interface MultiSelectOptions<Options extends Option<Value>[], Value extends Primitive> { 120 121 message: string; 121 122 options: Options; 122 123 initialValue?: Options[number]['value'][]; 123 124 cursorAt?: Options[number]["value"] 124 125 } 125 126 126 - export const select = <Options extends Option<Value>[], Value extends Readonly<string>>( 127 + export const select = <Options extends Option<Value>[], Value extends Primitive>( 127 128 opts: SelectOptions<Options, Value> 128 129 ) => { 129 130 const opt = ( 130 131 option: Options[number], 131 132 state: "inactive" | "active" | "selected" | "cancelled" 132 133 ) => { 133 - const label = option.label ?? option.value; 134 + const label = option.label ?? String(option.value); 134 135 if (state === "active") { 135 136 return `${color.green("●")} ${label} ${ 136 137 option.hint ? color.dim(`(${option.hint})`) : "" ··· 174 175 }).prompt() as Promise<Options[number]['value'] | symbol>; 175 176 }; 176 177 177 - export const multiselect = <Options extends Option<Value>[], Value extends Readonly<string>>(opts: MultiSelectOptions<Options, Value>) => { 178 + export const multiselect = <Options extends Option<Value>[], Value extends Primitive>(opts: MultiSelectOptions<Options, Value>) => { 178 179 const opt = (option: Options[number], state: 'inactive' | 'active' | 'selected' | 'active-selected' | 'submitted' | 'cancelled') => { 179 - const label = option.label ?? option.value; 180 + const label = option.label ?? String(option.value); 180 181 if (state === 'active') { 181 182 return `${color.cyan('◻')} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ''}` 182 183 } else if (state === 'selected') {