mokkabonna / inquirer-autocomplete-prompt

Autocomplete prompt for inquirer
ISC License
350 stars 82 forks source link

TypeError: this.line.substring is not a function #129

Closed ElvisWong closed 1 year ago

ElvisWong commented 3 years ago

It crashes when I tab on "Tab" button for autocomplete. This is how I works with inquirer modules.

await inquirer.prompt([
  {
      type: "autocomplete",
      name: "product",
      message: `test`,
      suggestOnly: true,
      source: function (ans, input) {
        return new Promise(async function (res) {
          const search = input
            ? await Product.find({
                name: { $regex: new RegExp(input, `i`) },
              }).lean()
            : [];
          const choices = search.map((x) => ({
            name: x.name,
            value: x,
          }));
          res(choices);
        });
      },
    },
]);

image

This error happens when I set value as object to the source function. Once I changed back the value to string, It works fine.

mokkabonna commented 1 year ago

I can no longer reproduce this. Keep in mind also that with suggestonly it is basically a regular text input. So if you have an object there that is not really supported.

mokkabonna commented 1 year ago

Attempted this, pressing tab works fine.

https://github.com/mokkabonna/inquirer-autocomplete-prompt/commit/644f8704b8ed487f02a86d36fbdeeede554cdac7