Skip to content

Select mode returns 1 for falsy values #187

@tomchambers2

Description

@tomchambers2

Describe the bug

You can't get a true/false out of the select choices. I realise you could use the confirm prompt in many cases, but in my case I want a yes/no/quit dialog. However false or 0 returns 1 as the selection.

To Reproduce

const prompts = require("prompts");

const test = async () => {
  const data = await prompts({
    type: "select",
    name: "test",
    message: `do you like ice cream`,
    choices: [
      {
        title: "Yes",
        value: true
      },
      { title: "No", value: false },
      { title: "Third random option", value: 'other' },
    ]
  });

  console.log(data);
};

test();

Results

selene:social-graph-2 tomchambers$ node tools/test.js 
✔ do you like ice cream › No
{ test: 1 }
selene:social-graph-2 tomchambers$ node tools/test.js 
✔ do you like ice cream › Yes
{ test: true }
selene:social-graph-2 tomchambers$ 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions