Skip to content

Commit 593f93d

Browse files
authored
feat: improve group types for readability (#105)
- Unwrap complex internal types to a top level one - Omit group results current key
1 parent f44c104 commit 593f93d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/prompts/src/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -654,15 +654,19 @@ export type PromptGroupAwaitedReturn<T> = {
654654

655655
export interface PromptGroupOptions<T> {
656656
/**
657-
* Control how the group can be canceld
658-
* if one of the prompts is canceld.
657+
* Control how the group can be canceled
658+
* if one of the prompts is canceled.
659659
*/
660-
onCancel?: (opts: { results: Partial<PromptGroupAwaitedReturn<T>> }) => void;
660+
onCancel?: (opts: { results: Prettify<Partial<PromptGroupAwaitedReturn<T>>> }) => void;
661661
}
662662

663+
type Prettify<T> = {
664+
[P in keyof T]: T[P];
665+
} & {};
666+
663667
export type PromptGroup<T> = {
664668
[P in keyof T]: (opts: {
665-
results: Partial<PromptGroupAwaitedReturn<T>>;
669+
results: Prettify<Partial<PromptGroupAwaitedReturn<Omit<T, P>>>>;
666670
}) => void | Promise<T[P] | void>;
667671
};
668672

@@ -673,7 +677,7 @@ export type PromptGroup<T> = {
673677
export const group = async <T>(
674678
prompts: PromptGroup<T>,
675679
opts?: PromptGroupOptions<T>
676-
): Promise<PromptGroupAwaitedReturn<T>> => {
680+
): Promise<Prettify<PromptGroupAwaitedReturn<T>>> => {
677681
const results = {} as any;
678682
const promptNames = Object.keys(prompts);
679683

0 commit comments

Comments
 (0)