Autocomplete type doesn't respect empty value choice
Author: Josh-CenaCreated Jan 3, 2022Updated Mar 25, 2025
Describe the bug
When choices.value is empty (''), the return value of autocomplete is the title instead of the empty string.
To Reproduce
(async () => {
const response = await prompts({
type: 'autocomplete',
name: 'res',
message: 'Pick your favorite actor',
choices: [
{ title: 'A', value: 'A-value' },
{ title: 'B', value: '' },
]
});
console.log(response);
})();Select B.
Expected behavior
Logs { res: '' }.
Actually logs { res: 'B' }. If the value is non-empty, e.g. if A is selected, then A-value is correctly logged.
If the type is changed to select, then the empty string is correctly logged, making me think this is a bug.
System
- OS: MacOS 11.6.2
- Terminal: Bash
- Node version: 17.2.0
Source: terkelg/prompts