[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.

select prompts: support complex value types

authored by

Oskar Löfgren and committed by
Nate Moore
(Mar 5, 2023, 10:11 AM -0600) cb1111ef a038296a

+16 -11
+5
.changeset/olive-birds-brush.md
··· 1 + --- 2 + "@clack/prompts": patch 3 + --- 4 + 5 + Support complex value types for `select`, `multiselect` and `groupMultiselect`.
+11 -11
packages/prompts/src/index.ts
··· 169 169 }; 170 170 171 171 type Primitive = Readonly<string | boolean | number>; 172 - interface Option<Value extends Primitive> { 173 - value: Value; 174 - label?: string; 175 - hint?: string; 176 - } 177 - export interface SelectOptions<Options extends Option<Value>[], Value extends Primitive> { 172 + 173 + type Option<Value> = Value extends Primitive 174 + ? { value: Value; label?: string; hint?: string } 175 + : { value: Value; label: string; hint?: string }; 176 + 177 + export interface SelectOptions<Options extends Option<Value>[], Value> { 178 178 message: string; 179 179 options: Options; 180 180 initialValue?: Value; 181 181 } 182 182 183 - export const select = <Options extends Option<Value>[], Value extends Primitive>( 183 + export const select = <Options extends Option<Value>[], Value>( 184 184 opts: SelectOptions<Options, Value> 185 185 ) => { 186 186 const opt = (option: Option<Value>, state: 'inactive' | 'active' | 'selected' | 'cancelled') => { ··· 269 269 }).prompt() as Promise<Value | symbol>; 270 270 }; 271 271 272 - export interface MultiSelectOptions<Options extends Option<Value>[], Value extends Primitive> { 272 + export interface MultiSelectOptions<Options extends Option<Value>[], Value> { 273 273 message: string; 274 274 options: Options; 275 275 initialValues?: Value[]; 276 276 required?: boolean; 277 277 cursorAt?: Value; 278 278 } 279 - export const multiselect = <Options extends Option<Value>[], Value extends Primitive>( 279 + export const multiselect = <Options extends Option<Value>[], Value>( 280 280 opts: MultiSelectOptions<Options, Value> 281 281 ) => { 282 282 const opt = ( ··· 387 387 }).prompt() as Promise<Value[] | symbol>; 388 388 }; 389 389 390 - export interface GroupMultiSelectOptions<Options extends Option<Value>[], Value extends Primitive> { 390 + export interface GroupMultiSelectOptions<Options extends Option<Value>[], Value> { 391 391 message: string; 392 392 options: Record<string, Options>; 393 393 initialValues?: Value[]; 394 394 required?: boolean; 395 395 cursorAt?: Value; 396 396 } 397 - export const groupMultiselect = <Options extends Option<Value>[], Value extends Primitive>( 397 + export const groupMultiselect = <Options extends Option<Value>[], Value>( 398 398 opts: GroupMultiSelectOptions<Options, Value> 399 399 ) => { 400 400 const opt = (