将答案传递给 InquirerJS 中的选择?

Passing an answer to choices in InquirerJS?

我怎样才能从上一个问题得到答案并转到下一个问题以选择 inquirerJS?我知道它是异步的,但我不确定如何在这里创建承诺。任何进一步的见解和帮助都会很棒。

示例:

var questions = [{
    name: 'menu',
    type: 'checkbox',
    message: 'Which food do you like eating?',
    choices: ['pizza', 'hotdog', 'hamburger', 'sandwiches'],
   }, {
    name: 'favorite',
    type: 'checkbox',
    message: 'Which one do you like most?',
    choices: answers.menu,   <------- doesn't work because it is asynchronous
   };

根据文档 choises 可以是一个函数。

var inquirer = require('inquirer');

var questions = [
  {
    name: 'menu',
    type: 'checkbox',
    message: 'Which food do you like eating?',
    choices: ['pizza', 'hotdog', 'hamburger', 'sandwiches'],
  },
  {
    name: 'favorite',
    type: 'checkbox',
    message: 'Which one do you like most?',
    choices: (answers) => {
        return answers.menu;
    }
  },
];

inquirer.prompt(questions).then(answers => {
  console.log(answers);
});