mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 08:17:05 +00:00
Merge pull request #33736 from chigix/master
fix(inquirer): update api definitions to 6.x
This commit is contained in:
Vendored
+85
-62
@@ -1,4 +1,4 @@
|
||||
// Type definitions for Inquirer.js
|
||||
// Type definitions for Inquirer.js 6.x
|
||||
// Project: https://github.com/SBoudrias/Inquirer.js
|
||||
// Definitions by: Qubo <https://github.com/tkQubo>
|
||||
// Parvez <https://github.com/ppathan>
|
||||
@@ -9,27 +9,26 @@
|
||||
// Justin Rockwood <https://github.com/jrockwood>
|
||||
// Keith Kelly <https://github.com/kwkelly>
|
||||
// Junyoung Clare Jang <https://github.com/Ailrun>
|
||||
// Richard Lea <https://github.com/chigix>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
// TypeScript Version: 2.3
|
||||
/// <reference types="rx" />
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import through = require('through');
|
||||
import { Observable } from 'rxjs';
|
||||
import * as readline from 'readline';
|
||||
|
||||
declare namespace inquirer {
|
||||
type Prompts = { [name: string]: PromptModule };
|
||||
type Prompts = { [name: string]: prompts.Base };
|
||||
type ChoiceType = string | objects.ChoiceOption | objects.Separator;
|
||||
type Questions<T = Answers> =
|
||||
| Question<T>
|
||||
| ReadonlyArray<Question<T>>
|
||||
| Rx.Observable<Question<T>>;
|
||||
interface OutputStreamOption {
|
||||
output: NodeJS.WriteStream
|
||||
}
|
||||
interface InputStreamOption {
|
||||
input: NodeJS.ReadStream
|
||||
}
|
||||
type StreamOptions = InputStreamOption | OutputStreamOption | (InputStreamOption & OutputStreamOption);
|
||||
| Observable<Question<T>>;
|
||||
type StreamOptions = {
|
||||
input?: NodeJS.ReadStream,
|
||||
output?: NodeJS.WriteStream,
|
||||
};
|
||||
|
||||
interface Inquirer {
|
||||
restoreDefaultPrompts(): void;
|
||||
@@ -47,28 +46,25 @@ declare namespace inquirer {
|
||||
/**
|
||||
* Public CLI helper interface
|
||||
* @param questions Questions settings array
|
||||
* @param cb Callback being passed the user answers
|
||||
* @return
|
||||
*/
|
||||
prompt<T>(questions: Questions<T>, cb: (answers: T) => any): ui.Prompt;
|
||||
prompt<T>(questions: Questions<T>): Promise<T>;
|
||||
prompt: PromptModule;
|
||||
prompts: Prompts;
|
||||
Separator: objects.SeparatorStatic;
|
||||
ui: {
|
||||
BottomBar: ui.BottomBar;
|
||||
Prompt: ui.Prompt;
|
||||
Prompt: ui.PromptUI;
|
||||
};
|
||||
}
|
||||
|
||||
interface PromptModule {
|
||||
<T>(questions: Questions<T>): Promise<T>;
|
||||
<T>(questions: Questions<T>, cb: (answers: T) => any): ui.Prompt;
|
||||
<T>(questions: Questions<T>): Promise<T> & { ui: ui.PromptUI };
|
||||
/**
|
||||
* Register a prompt type
|
||||
* @param name Prompt type name
|
||||
* @param prompt Prompt constructor
|
||||
*/
|
||||
registerPrompt(name: string, prompt: PromptModule): ui.Prompt;
|
||||
registerPrompt(name: string, prompt: prompts.Base): PromptModule;
|
||||
/**
|
||||
* Register the defaults provider prompts
|
||||
*/
|
||||
@@ -111,9 +107,9 @@ declare namespace inquirer {
|
||||
* (to save in the answers hash). Values can also be a Separator.
|
||||
*/
|
||||
choices?:
|
||||
| ReadonlyArray<ChoiceType>
|
||||
| ((answers: T) => ReadonlyArray<ChoiceType>)
|
||||
| ((answers: T) => Promise<ReadonlyArray<ChoiceType>>);
|
||||
| ReadonlyArray<ChoiceType>
|
||||
| ((answers: T) => ReadonlyArray<ChoiceType>)
|
||||
| ((answers: T) => Promise<ReadonlyArray<ChoiceType>>);
|
||||
/**
|
||||
* Receive the user input and should return true if the value is valid, and an error message (String)
|
||||
* otherwise. If false is returned, a default error message is provided.
|
||||
@@ -161,32 +157,88 @@ declare namespace inquirer {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Corresponding to the answer object creation in:
|
||||
* https://github.com/SBoudrias/Inquirer.js/blob/ff075f587ef78504f0eae4ee5ca0656432429026/packages/inquirer/lib/ui/prompt.js#L88
|
||||
*/
|
||||
interface Answer {
|
||||
name: string,
|
||||
answer: any,
|
||||
}
|
||||
|
||||
namespace prompts {
|
||||
/**
|
||||
* Base prompt implementation
|
||||
* Should be extended by prompt types.
|
||||
*
|
||||
* @interface Base
|
||||
*/
|
||||
interface Base {
|
||||
new <T>(question: Question<T>, rl: readline.Interface, answers: Answers): Base;
|
||||
/**
|
||||
* Start the Inquiry session and manage output value filtering
|
||||
*
|
||||
* @returns {Promise<any>}
|
||||
* @memberof Base
|
||||
*/
|
||||
run(): Promise<any>;
|
||||
/**
|
||||
* Called when the UI closes. Override to do any specific cleanup necessary
|
||||
*/
|
||||
close(): void;
|
||||
/**
|
||||
* Generate the prompt question string
|
||||
*/
|
||||
getQuestion(): string;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
|
||||
/**
|
||||
* Base interface class other can inherits from
|
||||
*/
|
||||
interface Prompt extends BaseUI<Prompts> {
|
||||
new (promptModule: Prompts): Prompt;
|
||||
interface BaseUI {
|
||||
rl: readline.Interface;
|
||||
new(opt: StreamOptions): BaseUI;
|
||||
/**
|
||||
* Handle the ^C exit
|
||||
* @return {null}
|
||||
*/
|
||||
onForceClose(): void;
|
||||
/**
|
||||
* Close the interface and cleanup listeners
|
||||
*/
|
||||
close(): void;
|
||||
}
|
||||
/**
|
||||
* Base interface class other can inherits from
|
||||
*/
|
||||
interface PromptUI extends BaseUI {
|
||||
process: Observable<Answer>;
|
||||
new(prompts: Prompts, opt: StreamOptions): PromptUI;
|
||||
run<T>(questions: Questions<T>): Promise<Answers>;
|
||||
/**
|
||||
* Once all prompt are over
|
||||
*/
|
||||
onCompletion(): void;
|
||||
processQuestion<T>(question: Question<T>): any;
|
||||
fetchAnswer<T>(question: Question<T>): any;
|
||||
setDefaultType<T>(question: Question<T>): any;
|
||||
filterIfRunnable<T>(question: Question<T>): any;
|
||||
processQuestion<T>(question: Question<T>): Observable<Question<T>>;
|
||||
fetchAnswer<T>(question: Question<T>): Observable<Question<T>>;
|
||||
setDefaultType<T>(question: Question<T>): Observable<Question<T>>;
|
||||
filterIfRunnable<T>(question: Question<T>): Observable<Question<T>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sticky bottom bar user interface
|
||||
*/
|
||||
interface BottomBar extends BaseUI<BottomBarOption> {
|
||||
new (opt?: BottomBarOption): BottomBar;
|
||||
interface BottomBar extends BaseUI {
|
||||
new(opt?: StreamOptions & { bottomBar?: string }): BottomBar;
|
||||
/**
|
||||
* Render the prompt to screen
|
||||
* @return self
|
||||
*/
|
||||
render(): BottomBar;
|
||||
clean(): BottomBar;
|
||||
/**
|
||||
* Update the bottom bar content and rerender
|
||||
* @param bottomBar Bottom bar content
|
||||
@@ -194,10 +246,11 @@ declare namespace inquirer {
|
||||
*/
|
||||
updateBottomBar(bottomBar: string): BottomBar;
|
||||
/**
|
||||
* Rerender the prompt
|
||||
* Write out log data
|
||||
* @param {String} data - The log data to be output
|
||||
* @return self
|
||||
*/
|
||||
writeLog(data: any): BottomBar;
|
||||
writeLog(data: string): BottomBar;
|
||||
/**
|
||||
* Make sure line end on a line feed
|
||||
* @param str Input string
|
||||
@@ -212,36 +265,6 @@ declare namespace inquirer {
|
||||
log: through.ThroughStream;
|
||||
}
|
||||
|
||||
interface BottomBarOption {
|
||||
bottomBar?: string;
|
||||
}
|
||||
/**
|
||||
* Base interface class other can inherits from
|
||||
*/
|
||||
interface BaseUI<TOpt> {
|
||||
new (opt: TOpt): void;
|
||||
/**
|
||||
* Handle the ^C exit
|
||||
* @return {null}
|
||||
*/
|
||||
onForceClose(): void;
|
||||
/**
|
||||
* Close the interface and cleanup listeners
|
||||
*/
|
||||
close(): void;
|
||||
/**
|
||||
* Handle and propagate keypress events
|
||||
*/
|
||||
onKeypress(s: string, key: Key): void;
|
||||
}
|
||||
|
||||
interface Key {
|
||||
sequence: string;
|
||||
name: string;
|
||||
meta: boolean;
|
||||
shift: boolean;
|
||||
ctrl: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
namespace objects {
|
||||
|
||||
@@ -3,11 +3,10 @@ import inquirer = require("inquirer");
|
||||
inquirer.prompt(
|
||||
[
|
||||
/* Pass your questions in here */
|
||||
],
|
||||
function(answers: inquirer.Answers) {
|
||||
// Use user feedback for... whatever!!
|
||||
}
|
||||
);
|
||||
]
|
||||
).then((answers: inquirer.Answers) => {
|
||||
// Use user feedback for... whatever!!
|
||||
});
|
||||
|
||||
//
|
||||
// examples/bottom-bar.js
|
||||
@@ -87,11 +86,10 @@ inquirer.prompt<{ toppings: string }>(
|
||||
return true;
|
||||
}
|
||||
}
|
||||
],
|
||||
function(answers) {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
}
|
||||
);
|
||||
]
|
||||
).then(answers => {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
});
|
||||
|
||||
//
|
||||
// examples/expand.js
|
||||
@@ -134,11 +132,10 @@ inquirer.prompt(
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
function(answers: inquirer.Answers) {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
}
|
||||
);
|
||||
]
|
||||
).then((answers: inquirer.Answers) => {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
});
|
||||
|
||||
//
|
||||
// examples/input.js
|
||||
@@ -184,9 +181,9 @@ var questions = [
|
||||
}
|
||||
];
|
||||
|
||||
inquirer.prompt(questions, function(answers) {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
});
|
||||
inquirer.prompt(questions).then(
|
||||
answers => console.log(JSON.stringify(answers, null, " "))
|
||||
);
|
||||
|
||||
//
|
||||
// examples/list.js
|
||||
@@ -222,11 +219,10 @@ inquirer.prompt(
|
||||
return val.toLowerCase();
|
||||
}
|
||||
}
|
||||
],
|
||||
function(answers: inquirer.Answers) {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
}
|
||||
);
|
||||
]
|
||||
).then((answers: inquirer.Answers) => {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
});
|
||||
|
||||
//
|
||||
// examples/long-list.js
|
||||
@@ -263,11 +259,10 @@ inquirer.prompt(
|
||||
paginated: true,
|
||||
choices: choices
|
||||
}
|
||||
],
|
||||
function(answers: inquirer.Answers) {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
}
|
||||
);
|
||||
]
|
||||
).then((answers: inquirer.Answers) => {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
});
|
||||
|
||||
//
|
||||
// examples/nested-call.js
|
||||
@@ -286,16 +281,15 @@ inquirer.prompt(
|
||||
name: "chocolate",
|
||||
message: "What's your favorite chocolate?",
|
||||
choices: ["Mars", "Oh Henry", "Hershey"]
|
||||
},
|
||||
function(answers: inquirer.Answers) {
|
||||
inquirer.prompt({
|
||||
type: "list",
|
||||
name: "beverage",
|
||||
message: "And your favorite beverage?",
|
||||
choices: ["Pepsi", "Coke", "7up", "Mountain Dew", "Red Bull"]
|
||||
});
|
||||
}
|
||||
);
|
||||
).then((answers: inquirer.Answers) => {
|
||||
inquirer.prompt({
|
||||
type: "list",
|
||||
name: "beverage",
|
||||
message: "And your favorite beverage?",
|
||||
choices: ["Pepsi", "Coke", "7up", "Mountain Dew", "Red Bull"]
|
||||
});
|
||||
});
|
||||
|
||||
//
|
||||
// examples/password.js
|
||||
@@ -315,11 +309,10 @@ inquirer.prompt(
|
||||
message: "Enter your git password",
|
||||
name: "password"
|
||||
}
|
||||
],
|
||||
function(answers: inquirer.Answers) {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
}
|
||||
);
|
||||
]
|
||||
).then((answers: inquirer.Answers) => {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
});
|
||||
|
||||
//
|
||||
// examples/pizza.js
|
||||
@@ -421,7 +414,7 @@ var questions2 = [
|
||||
}
|
||||
];
|
||||
|
||||
inquirer.prompt(questions, function(answers) {
|
||||
inquirer.prompt(questions).then(answers => {
|
||||
console.log("\nOrder receipt:");
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
});
|
||||
@@ -460,11 +453,10 @@ inquirer.prompt(
|
||||
return val.toLowerCase();
|
||||
}
|
||||
}
|
||||
],
|
||||
function(answers: inquirer.Answers) {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
}
|
||||
);
|
||||
]
|
||||
).then((answers: inquirer.Answers) => {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
});
|
||||
|
||||
//
|
||||
// examples/recursive.js
|
||||
@@ -495,9 +487,8 @@ var questions3 = [
|
||||
];
|
||||
|
||||
function ask() {
|
||||
inquirer.prompt<{ tvShow: string; askAgain: boolean }>(questions3, function(
|
||||
answers
|
||||
) {
|
||||
inquirer.prompt<{ tvShow: string; askAgain: boolean }>(questions3)
|
||||
.then((answers) => {
|
||||
output2.push(answers.tvShow);
|
||||
if (answers.askAgain) {
|
||||
ask();
|
||||
@@ -560,7 +551,7 @@ function likesFood(aFood: string) {
|
||||
};
|
||||
}
|
||||
|
||||
inquirer.prompt<Answers4>(questions, function(answers) {
|
||||
inquirer.prompt<Answers4>(questions).then(answers => {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
});
|
||||
|
||||
@@ -579,11 +570,10 @@ inquirer.prompt(
|
||||
message: 'What do you want to do?',
|
||||
choices: immutableChoices
|
||||
}
|
||||
],
|
||||
function(answers: inquirer.Answers) {
|
||||
console.log(JSON.stringify(answers, null, ' '));
|
||||
}
|
||||
);
|
||||
]
|
||||
).then((answers: inquirer.Answers) => {
|
||||
console.log(JSON.stringify(answers, null, ' '));
|
||||
});
|
||||
|
||||
//
|
||||
// Other tests not covered in the examples provided with inquirer
|
||||
@@ -667,9 +657,10 @@ var questions = [
|
||||
}
|
||||
];
|
||||
|
||||
inquirer.createPromptModule({ output: process.stderr })(questions, function(answers) {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
});
|
||||
inquirer.createPromptModule({ output: process.stderr })(questions)
|
||||
.then(answers => {
|
||||
console.log(JSON.stringify(answers, null, " "));
|
||||
});
|
||||
|
||||
// Work with JS inquirer but rejected by typing.
|
||||
inquirer.prompt([
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"rxjs": ">=6.4.0"
|
||||
}
|
||||
}
|
||||
Vendored
+4
-2
@@ -5,11 +5,13 @@
|
||||
// Ika <https://github.com/ikatyang>
|
||||
// Joshua Cherry <https://github.com/tasadar2>
|
||||
// Arthur Corenzan <https://github.com/haggen>
|
||||
// Richard Lea <https://github.com/chigix>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
import * as inquirer from 'inquirer';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
type Callback = (err: any) => void;
|
||||
|
||||
@@ -20,7 +22,7 @@ declare namespace Generator {
|
||||
*/
|
||||
store?: boolean;
|
||||
}
|
||||
type Questions = Question | Question[] | Rx.Observable<Question>;
|
||||
type Questions = Question | Question[] | Observable<Question>;
|
||||
type Answers = inquirer.Answers;
|
||||
|
||||
class Storage {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"rxjs": ">=6.4.0"
|
||||
}
|
||||
}
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@
|
||||
// Project: https://github.com/yeoman/yeoman-test, http://yeoman.io/authoring/testing.html
|
||||
// Definitions by: Ika <https://github.com/ikatyang>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
import Generator = require('yeoman-generator');
|
||||
|
||||
Reference in New Issue
Block a user