title: How can I auto answer questions in inquirer.js?
body: <p>I'm writing a small CLI in typescript and I have a command which basically allows me to generate a json file with default values in it (just like <code>npm init -y</code>), but I don't know how to auto answer the questions in inquirer.</p>
  <p>This is what I've got so far:</p>
  <pre><code>export const initializeConfig = (project: string, ...args: boolean[]) =&gt; {
    prompt([
      {
        type: &quot;input&quot;,
        name: &quot;name&quot;,
        message: &quot;What is the name of the project?&quot;,
        default: basename(cwd()),
        when: () =&gt; args.every((arg) =&gt; arg === false),
      },
      {
        type: &quot;list&quot;,
        name: &quot;project&quot;,
        message: &quot;What is the type of the project?&quot;,
        choices: [&quot;Node&quot;, &quot;Python&quot;],
        default: project,
        when: () =&gt; args.every((arg) =&gt; arg === false),
      },
    ])
      .then((answers: Answers) =&gt; {
        config = setConfig({ name: answers.name });
        config = setConfig({ project: answers.project });
      })
      .then(() =&gt;
        prompt([
          {
            type: &quot;input&quot;,
            name: &quot;path&quot;,
            message: &quot;Where is your project root located?&quot;,
            default: &quot;.&quot;,
            when: () =&gt; args.every((arg) =&gt; arg === false),
          },
          {
            type: &quot;input&quot;,
            name: &quot;ignore&quot;,
            message: &quot;What do you want to ignore? (comma separated)&quot;,
            default: defaultIgnores(config.project).ignore,
            when: () =&gt; args.every((arg) =&gt; arg === false),
          },
        ]).then((answers: Answers) =&gt; {
          config = setConfig(ignoreFiles(config.project, answers.ignore));
          createConfig(answers.path, config);
        })
      );
  };
  </code></pre>
  <p>I thought that if I'd skip/hide the questions with <code>when()</code>, it would use the default values, but it doesn't. It's always <code>undefined</code>.</p>
  <p>Didn't find this topic on the internet so far. Any ideas?</p>