Skip to content

Commit

Permalink
Exports Option type (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re authored Jan 9, 2025
1 parent 1904e57 commit 98925e3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-olives-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clack/prompts": patch
---

Exports the `Option` type and improves JSDocannotations
40 changes: 37 additions & 3 deletions packages/prompts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,43 @@ export const confirm = (opts: ConfirmOptions) => {

type Primitive = Readonly<string | boolean | number>;

type Option<Value> = Value extends Primitive
? { value: Value; label?: string; hint?: string }
: { value: Value; label: string; hint?: string };
export type Option<Value> = Value extends Primitive
? {
/**
* Internal data for this option.
*/
value: Value;
/**
* The optional, user-facing text for this option.
*
* By default, the `value` is converted to a string.
*/
label?: string;
/**
* An optional hint to display to the user when
* this option might be selected.
*
* By default, no `hint` is displayed.
*/
hint?: string;
}
: {
/**
* Internal data for this option.
*/
value: Value;
/**
* Required. The user-facing text for this option.
*/
label: string;
/**
* An optional hint to display to the user when
* this option might be selected.
*
* By default, no `hint` is displayed.
*/
hint?: string;
};

export interface SelectOptions<Value> {
message: string;
Expand Down

0 comments on commit 98925e3

Please sign in to comment.