Skip to content
Open
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
10 changes: 3 additions & 7 deletions packages/prompts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,16 +844,12 @@ export const spinner = ({ indicator = 'dots' }: SpinnerOptions = {}) => {
};
};

export type PromptGroupAwaitedReturn<T> = {
[P in keyof T]: Exclude<Awaited<T[P]>, symbol>;
};

export interface PromptGroupOptions<T> {
/**
* Control how the group can be canceled
* if one of the prompts is canceled.
*/
onCancel?: (opts: { results: Prettify<Partial<PromptGroupAwaitedReturn<T>>> }) => void;
onCancel?: (opts: { results: Prettify<Partial<T>> }) => void;
}

type Prettify<T> = {
Expand All @@ -862,7 +858,7 @@ type Prettify<T> = {

export type PromptGroup<T> = {
[P in keyof T]: (opts: {
results: Prettify<Partial<PromptGroupAwaitedReturn<Omit<T, P>>>>;
results: Record<PropertyKey, unknown>;
}) => undefined | Promise<T[P] | undefined>;
};

Expand All @@ -873,7 +869,7 @@ export type PromptGroup<T> = {
export const group = async <T>(
prompts: PromptGroup<T>,
opts?: PromptGroupOptions<T>
): Promise<Prettify<PromptGroupAwaitedReturn<T>>> => {
): Promise<Prettify<T>> => {
const results = {} as any;
const promptNames = Object.keys(prompts);

Expand Down