Skip to content

Commit

Permalink
Fix complex value return type inference (bombshell-dev#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpreston321 committed Aug 23, 2023
2 parents ef7d414 + c8c4e16 commit 7c7fde8
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions packages/prompts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,14 @@ type Option<Value> = Value extends Primitive
? { value: Value; label?: string; hint?: string }
: { value: Value; label: string; hint?: string };

export interface SelectOptions<Options extends Option<Value>[], Value> {
export interface SelectOptions<Value> {
message: string;
options: Options;
options: Option<Value>[];
initialValue?: Value;
maxItems?: number;
}

export const select = <Options extends Option<Value>[], Value>(
opts: SelectOptions<Options, Value>
) => {
export const select = <Value>(opts: SelectOptions<Value>) => {
const opt = (option: Option<Value>, state: 'inactive' | 'active' | 'selected' | 'cancelled') => {
const label = option.label ?? String(option.value);
if (state === 'active') {
Expand Down Expand Up @@ -253,9 +251,7 @@ export const select = <Options extends Option<Value>[], Value>(
}).prompt() as Promise<Value | symbol>;
};

export const selectKey = <Options extends Option<Value>[], Value extends string>(
opts: SelectOptions<Options, Value>
) => {
export const selectKey = <Value extends string>(opts: SelectOptions<Value>) => {
const opt = (
option: Option<Value>,
state: 'inactive' | 'active' | 'selected' | 'cancelled' = 'inactive'
Expand Down Expand Up @@ -301,16 +297,14 @@ export const selectKey = <Options extends Option<Value>[], Value extends string>
}).prompt() as Promise<Value | symbol>;
};

export interface MultiSelectOptions<Options extends Option<Value>[], Value> {
export interface MultiSelectOptions<Value> {
message: string;
options: Options;
options: Option<Value>[];
initialValues?: Value[];
required?: boolean;
cursorAt?: Value;
}
export const multiselect = <Options extends Option<Value>[], Value>(
opts: MultiSelectOptions<Options, Value>
) => {
export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
const opt = (
option: Option<Value>,
state: 'inactive' | 'active' | 'selected' | 'active-selected' | 'submitted' | 'cancelled'
Expand Down Expand Up @@ -419,16 +413,14 @@ export const multiselect = <Options extends Option<Value>[], Value>(
}).prompt() as Promise<Value[] | symbol>;
};

export interface GroupMultiSelectOptions<Options extends Option<Value>[], Value> {
export interface GroupMultiSelectOptions<Value> {
message: string;
options: Record<string, Options>;
options: Record<string, Option<Value>[]>;
initialValues?: Value[];
required?: boolean;
cursorAt?: Value;
}
export const groupMultiselect = <Options extends Option<Value>[], Value>(
opts: GroupMultiSelectOptions<Options, Value>
) => {
export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) => {
const opt = (
option: Option<Value>,
state:
Expand Down

0 comments on commit 7c7fde8

Please sign in to comment.