Inquirer.js icon indicating copy to clipboard operation
Inquirer.js copied to clipboard

"message" does not appear to be supporting 'typeof Function', contrary to docs.

Open jackbackes opened this issue 9 years ago • 3 comments

According to the docs, message can take either a String or a Function:

message: (String|Function) The question to print. If defined as a function, the first parameter will be the current inquirer session answers.

So, I would expect the following question object to print the previous answers in the prompt:

{
      type: 'confirm',
      name: 'confirmCreateComponent',
      message: function (answers) {
        return (
          `Are you sure you would like to create the following component?
          name: <${answers.ComponentName} />
          type: ${answers.componentType}
          location: ${path.join(__dirname, answers.dir)}
          `
        );
      },

Instead, it prints the function body in the prompt:

? [COMPONENT] function (answers) {
    return (
      `Are you sure you would like to create the following component?
      name: <${answers.ComponentName} />
      type: ${answers.componentType}
      location: ${path.join(__dirname, answers.dir)}
      `
    );
  } (Y/n)

Am I misunderstanding the docs?

jackbackes avatar Nov 03 '16 00:11 jackbackes

Looks like this should work. It's possible we broke something at some point during a release and no one realized? (might even just be a bug with the confirm prompt...)

SBoudrias avatar Nov 03 '16 00:11 SBoudrias

is this something that was fixed in a previous version? I just realized that Plop.js is using [email protected]

jackbackes avatar Nov 03 '16 00:11 jackbackes

Oh quite possible then, would you mind testing on the latest release?

SBoudrias avatar Nov 03 '16 00:11 SBoudrias