Merge pull request #27960 from Ailrun/fix-inquirer

Update inquirer filter and validate to use any
This commit is contained in:
Benjamin Lichtman
2018-08-14 10:22:30 -07:00
committed by GitHub
2 changed files with 17 additions and 2 deletions
+3 -2
View File
@@ -8,6 +8,7 @@
// Synarque <https://github.com/synarque>
// Justin Rockwood <https://github.com/jrockwood>
// Keith Kelly <https://github.com/kwkelly>
// Junyoung Clare Jang <https://github.com/Ailrun>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -116,12 +117,12 @@ declare namespace inquirer {
* 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.
*/
validate?(input: string, answers?: T): boolean | string | Promise<boolean | string>;
validate?(input: any, answers?: T): boolean | string | Promise<boolean | string>;
/**
* Receive the user input and return the filtered value to be used inside the program.
* The value returned will be added to the Answers hash.
*/
filter?(input: string): string | Promise<string>;
filter?(input: string): any;
/**
* Receive the user input and return the transformed value to be displayed to the user. The
* transformation only impacts what is shown while editing. It does not impact the answers
+14
View File
@@ -670,3 +670,17 @@ var questions = [
inquirer.createPromptModule({ output: process.stderr })(questions, function(answers) {
console.log(JSON.stringify(answers, null, " "));
});
// Work with JS inquirer but rejected by typing.
inquirer.prompt([
{
type: "input",
name: "listOfThings",
filter(value: string): string[] {
return ["abc", "def"];
},
validate(value: string[]): boolean {
return value.length > 0;
}
}
]);