From a4956b02df1620315c0246ebfde78796d9d262e9 Mon Sep 17 00:00:00 2001 From: Junyoung Clare Jang Date: Wed, 8 Aug 2018 05:30:42 -0400 Subject: [PATCH] Update inquirer filter and validate to use any --- types/inquirer/index.d.ts | 5 +++-- types/inquirer/inquirer-tests.ts | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/types/inquirer/index.d.ts b/types/inquirer/index.d.ts index d00c037c71..5d976e896d 100644 --- a/types/inquirer/index.d.ts +++ b/types/inquirer/index.d.ts @@ -8,6 +8,7 @@ // Synarque // Justin Rockwood // Keith Kelly +// Junyoung Clare Jang // 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; + validate?(input: any, answers?: T): boolean | string | Promise; /** * 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; + 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 diff --git a/types/inquirer/inquirer-tests.ts b/types/inquirer/inquirer-tests.ts index 85a81d761e..4c8ba9491f 100644 --- a/types/inquirer/inquirer-tests.ts +++ b/types/inquirer/inquirer-tests.ts @@ -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; + } + } +]);