From 3e7a7de3bc0029f76a379ef71d1233419b8546db Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Fri, 7 Mar 2025 15:26:48 +0100 Subject: [PATCH] fix: weaken internal group types to strengthen return/onCancel types This changes a few things. First of all, trying to infer `T` while defining `T` currently doesn't work unless there's a member without the `results` arg. This is a known limitation that may or may not be fixed in typescript one day. Until that happens, if ever, this dumbs down the type of `results` to be a `Record`. This means _within a function_ you lose strong typing, but the return type will now always be correct. Secondly, `T` is actually the resulting already-awaited shape. This means we do not need `Awaited` since `T[K]` is already the awaited type. For example: ```ts type ActualType = { foo: number; bar: number; }; group({ foo: () => Promise.resolve(303), bar: () => Promise.resolve(808) }); ``` You can see the `ActualType` never needed `Awaited` on each type since it is already the final result. --- packages/prompts/src/index.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/prompts/src/index.ts b/packages/prompts/src/index.ts index e50ecf3a..fad0f628 100644 --- a/packages/prompts/src/index.ts +++ b/packages/prompts/src/index.ts @@ -844,16 +844,12 @@ export const spinner = ({ indicator = 'dots' }: SpinnerOptions = {}) => { }; }; -export type PromptGroupAwaitedReturn = { - [P in keyof T]: Exclude, symbol>; -}; - export interface PromptGroupOptions { /** * Control how the group can be canceled * if one of the prompts is canceled. */ - onCancel?: (opts: { results: Prettify>> }) => void; + onCancel?: (opts: { results: Prettify> }) => void; } type Prettify = { @@ -862,7 +858,7 @@ type Prettify = { export type PromptGroup = { [P in keyof T]: (opts: { - results: Prettify>>>; + results: Record; }) => undefined | Promise; }; @@ -873,7 +869,7 @@ export type PromptGroup = { export const group = async ( prompts: PromptGroup, opts?: PromptGroupOptions -): Promise>> => { +): Promise> => { const results = {} as any; const promptNames = Object.keys(prompts);