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

Exports Option type #229

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading