UNPKG

5.49 kBTypeScriptView Raw
1/**
2 * Inquirer.js
3 * A collection of common interactive command line user interfaces.
4 */
5import { Separator } from '@inquirer/prompts';
6import type { Prettify } from '@inquirer/type';
7import { default as PromptsRunner } from './ui/prompt.js';
8import type { LegacyPromptConstructor, PromptFn } from './ui/prompt.js';
9import type { Answers, CustomQuestion, UnnamedDistinctQuestion, StreamOptions } from './types.js';
10import { Observable } from 'rxjs';
11export type { QuestionMap, Question, DistinctQuestion, Answers, PromptSession, } from './types.js';
12type PromptReturnType<T> = Promise<Prettify<T>> & {
13 ui: PromptsRunner<Prettify<T>>;
14};
15/**
16 * Create a new self-contained prompt module.
17 */
18export declare function createPromptModule<Prompts extends Record<string, Record<string, unknown>> = never>(opt?: StreamOptions): {
19 <const A extends Answers, PrefilledAnswers extends Answers = object>(questions: ((UnnamedDistinctQuestion<PrefilledAnswers & A extends infer T ? { [K in keyof T]: (PrefilledAnswers & A)[K]; } : never> | CustomQuestion<PrefilledAnswers & A extends infer T ? { [K in keyof T]: (PrefilledAnswers & A)[K]; } : never, Prompts>) & {
20 name: Extract<keyof PrefilledAnswers, string> | Extract<keyof A, string>;
21 })[], answers?: PrefilledAnswers): PromptReturnType<Prettify<PrefilledAnswers & A>>;
22 <const A extends Answers, PrefilledAnswers extends Answers = object>(questions: { [name in keyof A]: UnnamedDistinctQuestion<PrefilledAnswers & A extends infer T ? { [K in keyof T]: (PrefilledAnswers & A)[K]; } : never> | CustomQuestion<PrefilledAnswers & A extends infer T ? { [K in keyof T]: (PrefilledAnswers & A)[K]; } : never, Prompts>; }, answers?: PrefilledAnswers): PromptReturnType<Prettify<PrefilledAnswers & Answers<Extract<keyof A, string>>>>;
23 <const A extends Answers, PrefilledAnswers extends Answers = object>(questions: Observable<(UnnamedDistinctQuestion<PrefilledAnswers & A extends infer T ? { [K in keyof T]: (PrefilledAnswers & A)[K]; } : never> | CustomQuestion<PrefilledAnswers & A extends infer T ? { [K in keyof T]: (PrefilledAnswers & A)[K]; } : never, Prompts>) & {
24 name: Extract<keyof PrefilledAnswers, string> | Extract<keyof A, string>;
25 }>, answers?: PrefilledAnswers): PromptReturnType<Prettify<PrefilledAnswers & A>>;
26 <const A extends Answers, PrefilledAnswers extends Answers = object>(questions: (UnnamedDistinctQuestion<A & PrefilledAnswers> | CustomQuestion<A & PrefilledAnswers, Prompts>) & {
27 name: Extract<keyof A, string> | Extract<keyof PrefilledAnswers, string>;
28 }, answers?: PrefilledAnswers): PromptReturnType<PrefilledAnswers & A>;
29 prompts: {
30 [x: string]: LegacyPromptConstructor | PromptFn<any, any>;
31 };
32 /**
33 * Register a prompt type
34 */
35 registerPrompt(name: string, prompt: LegacyPromptConstructor | PromptFn): any;
36 /**
37 * Register the defaults provider prompts
38 */
39 restoreDefaultPrompts(): void;
40};
41declare function registerPrompt(name: string, newPrompt: LegacyPromptConstructor): void;
42declare function restoreDefaultPrompts(): void;
43declare const inquirer: {
44 prompt: {
45 <const A extends Answers, PrefilledAnswers extends Answers = object>(questions: (UnnamedDistinctQuestion<PrefilledAnswers & A extends infer T ? { [K in keyof T]: (PrefilledAnswers & A)[K]; } : never> & {
46 name: Extract<keyof PrefilledAnswers, string> | Extract<keyof A, string>;
47 })[], answers?: PrefilledAnswers | undefined): PromptReturnType<PrefilledAnswers & A extends infer T ? { [K in keyof T]: (PrefilledAnswers & A)[K]; } : never>;
48 <const A extends Answers, PrefilledAnswers extends Answers = object>(questions: { [name in keyof A]: UnnamedDistinctQuestion<PrefilledAnswers & A extends infer T ? { [K in keyof T]: (PrefilledAnswers & A)[K]; } : never>; }, answers?: PrefilledAnswers | undefined): PromptReturnType<PrefilledAnswers & Answers<Extract<keyof A, string>> extends infer T_1 ? { [K_1 in keyof T_1]: (PrefilledAnswers & Answers<Extract<keyof A, string>>)[K_1]; } : never>;
49 <const A extends Answers, PrefilledAnswers extends Answers = object>(questions: Observable<UnnamedDistinctQuestion<PrefilledAnswers & A extends infer T ? { [K in keyof T]: (PrefilledAnswers & A)[K]; } : never> & {
50 name: Extract<keyof PrefilledAnswers, string> | Extract<keyof A, string>;
51 }>, answers?: PrefilledAnswers | undefined): PromptReturnType<PrefilledAnswers & A extends infer T ? { [K in keyof T]: (PrefilledAnswers & A)[K]; } : never>;
52 <const A extends Answers, PrefilledAnswers extends Answers = object>(questions: UnnamedDistinctQuestion<A & PrefilledAnswers> & {
53 name: Extract<keyof A, string> | Extract<keyof PrefilledAnswers, string>;
54 }, answers?: PrefilledAnswers | undefined): PromptReturnType<PrefilledAnswers & A>;
55 prompts: {
56 [x: string]: LegacyPromptConstructor | PromptFn<any, any>;
57 };
58 /**
59 * Register a prompt type
60 */
61 registerPrompt(name: string, prompt: LegacyPromptConstructor | PromptFn): any;
62 /**
63 * Register the defaults provider prompts
64 */
65 restoreDefaultPrompts(): void;
66 };
67 ui: {
68 Prompt: typeof PromptsRunner;
69 };
70 createPromptModule: typeof createPromptModule;
71 registerPrompt: typeof registerPrompt;
72 restoreDefaultPrompts: typeof restoreDefaultPrompts;
73 Separator: typeof Separator;
74};
75export default inquirer;