Skip to content

Commit c8c4e16

Browse files
Fix complex value return type inference
1 parent 593f93d commit c8c4e16

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

packages/prompts/src/index.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,13 @@ type Option<Value> = Value extends Primitive
174174
? { value: Value; label?: string; hint?: string }
175175
: { value: Value; label: string; hint?: string };
176176

177-
export interface SelectOptions<Options extends Option<Value>[], Value> {
177+
export interface SelectOptions<Value> {
178178
message: string;
179-
options: Options;
179+
options: Option<Value>[];
180180
initialValue?: Value;
181181
}
182182

183-
export const select = <Options extends Option<Value>[], Value>(
184-
opts: SelectOptions<Options, Value>
185-
) => {
183+
export const select = <Value>(opts: SelectOptions<Value>) => {
186184
const opt = (option: Option<Value>, state: 'inactive' | 'active' | 'selected' | 'cancelled') => {
187185
const label = option.label ?? String(option.value);
188186
if (state === 'active') {
@@ -221,9 +219,7 @@ export const select = <Options extends Option<Value>[], Value>(
221219
}).prompt() as Promise<Value | symbol>;
222220
};
223221

224-
export const selectKey = <Options extends Option<Value>[], Value extends string>(
225-
opts: SelectOptions<Options, Value>
226-
) => {
222+
export const selectKey = <Value extends string>(opts: SelectOptions<Value>) => {
227223
const opt = (
228224
option: Option<Value>,
229225
state: 'inactive' | 'active' | 'selected' | 'cancelled' = 'inactive'
@@ -269,16 +265,14 @@ export const selectKey = <Options extends Option<Value>[], Value extends string>
269265
}).prompt() as Promise<Value | symbol>;
270266
};
271267

272-
export interface MultiSelectOptions<Options extends Option<Value>[], Value> {
268+
export interface MultiSelectOptions<Value> {
273269
message: string;
274-
options: Options;
270+
options: Option<Value>[];
275271
initialValues?: Value[];
276272
required?: boolean;
277273
cursorAt?: Value;
278274
}
279-
export const multiselect = <Options extends Option<Value>[], Value>(
280-
opts: MultiSelectOptions<Options, Value>
281-
) => {
275+
export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
282276
const opt = (
283277
option: Option<Value>,
284278
state: 'inactive' | 'active' | 'selected' | 'active-selected' | 'submitted' | 'cancelled'
@@ -387,16 +381,14 @@ export const multiselect = <Options extends Option<Value>[], Value>(
387381
}).prompt() as Promise<Value[] | symbol>;
388382
};
389383

390-
export interface GroupMultiSelectOptions<Options extends Option<Value>[], Value> {
384+
export interface GroupMultiSelectOptions<Value> {
391385
message: string;
392-
options: Record<string, Options>;
386+
options: Record<string, Option<Value>[]>;
393387
initialValues?: Value[];
394388
required?: boolean;
395389
cursorAt?: Value;
396390
}
397-
export const groupMultiselect = <Options extends Option<Value>[], Value>(
398-
opts: GroupMultiSelectOptions<Options, Value>
399-
) => {
391+
export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) => {
400392
const opt = (
401393
option: Option<Value>,
402394
state:

0 commit comments

Comments
 (0)