2.38 kBTypeScriptView Raw
1import { input, select, number, confirm, rawlist, expand, checkbox, password, editor } from '@inquirer/prompts';
2import type { Prettify, KeyUnion, DistributiveMerge, Pick } from '@inquirer/type';
3import { Observable } from 'rxjs';
4export type Answers<Key extends string = string> = {
5 [key in Key]: any;
6};
7type AsyncCallbackFunction<R> = (...args: [error: null | undefined, value: R] | [error: Error, value: undefined]) => void;
8type AsyncGetterFunction<R, A extends Answers> = (this: {
9 async: () => AsyncCallbackFunction<R>;
10}, answers: Partial<A>) => void | R | Promise<R>;
11export interface QuestionMap {
12 input: Parameters<typeof input>[0];
13 select: Parameters<typeof select>[0];
14 /** @deprecated `list` is now named `select` */
15 list: Parameters<typeof select>[0];
16 number: Parameters<typeof number>[0];
17 confirm: Parameters<typeof confirm>[0];
18 rawlist: Parameters<typeof rawlist>[0];
19 expand: Parameters<typeof expand>[0];
20 checkbox: Parameters<typeof checkbox>[0];
21 password: Parameters<typeof password>[0];
22 editor: Parameters<typeof editor>[0];
23}
24type PromptConfigMap<A extends Answers> = {
25 [key in keyof QuestionMap]: Readonly<DistributiveMerge<QuestionMap[keyof QuestionMap], {
26 type: keyof QuestionMap;
27 name: KeyUnion<A>;
28 when?: AsyncGetterFunction<boolean, Prettify<A>> | boolean;
29 askAnswered?: boolean;
30 message: Pick<QuestionMap[keyof QuestionMap], 'message'> | AsyncGetterFunction<Pick<QuestionMap[keyof QuestionMap], 'message'>, Prettify<A>>;
31 choices?: Pick<QuestionMap[keyof QuestionMap], 'choices'> | string[] | AsyncGetterFunction<Pick<QuestionMap[keyof QuestionMap], 'choices'> | string[], Prettify<A>>;
32 default?: Pick<QuestionMap[keyof QuestionMap], 'default'> | AsyncGetterFunction<Pick<QuestionMap[keyof QuestionMap], 'default'> | string[], Prettify<A>>;
33 }>>;
34};
35export type Question<A extends Answers> = PromptConfigMap<A>[keyof PromptConfigMap<A>];
36export type QuestionAnswerMap<A extends Answers> = Readonly<{
37 [name in KeyUnion<A>]: Omit<Question<A>, 'name'>;
38}> | never;
39export type QuestionArray<A extends Answers> = readonly Question<A>[] | never;
40export type QuestionObservable<A extends Answers> = Observable<Question<A>> | never;
41export type StreamOptions = Prettify<Parameters<typeof input>[1] & {
42 skipTTYChecks?: boolean;
43}>;
44export {};