Closed felixfbecker closed 6 years ago
Hey @felixfbecker thanks for opening this issue.
I've already though about this as part of a refactor I want to see in Inquirer. It's not been progressing very fast right now, but if you're willing to, help would be welcomed. You can learn more about the refactor over here https://github.com/SBoudrias/Inquirer.js/issues/692
I'll close this issue as I'm not really open to release a major breaking changes without major changes to the core library.
I'm using this for now:
async function ask(question) {
return (await Inquirer.prompt({...question,name:'_'}))._
}
In my usage of
inquirer
, I've found that most prompts only ask a single question, i.e. I callprompt()
for every question individually. This is because the logic of when to ask which question is complicated and better expressed withif
statements than with thewhen
option.Using the
when
option is also not easy to make type safe, becauseprompt()
returns a question object with a key for every question, but there is no way to statically analyse which keys will be present or not. Withif
statements and individual calls toprompt()
, TypeScript (or Flow) can know for sure which values are there.However, using the current
prompt()
API is incredibly cumbersome for single questions, especially when using TypeScript:As you can see, I have to define the
name
three times (two times if using JS):options.name
I understand that the syntax for "bulk" asking questions was maybe convenient when Node was all callback based to avoid callback hell, but we now have Promise support in inquirer and async/await since Node 8.
Could we have an API for asking single questions? Something like
Way less boilerplate, and working type inference.