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

`createPromptModule` typing error : No overload matches this call. The last overload gave the following error.0

Open recursivezero opened this issue 1 year ago • 2 comments

With

  • Nodejs v 22.0
  • inquirer v 10.1.8
  • ubuntu v 24.04
  • typescript v 5.4.5
  • having "type": "module" in package.json
  • file name : /bin/ask.js
import inquirer from "inquirer";

const questions = [
  { type: "input", name: "packageName", message: "tell me package name", default: "template" }];
const prompt = inquirer.createPromptModule();

prompt(questions)
  .then((answers) => {
    // Use user feedback for... whatever!!
    console.log({ answers });
  })
  .catch((error) => {
    if (error.isTtyError) {
      // Prompt couldn't be rendered in the current environment
    } else {
      // Something else went wrong
    }
  });

although it works when run but vs code gives ts lint error as below

No overload matches this call.
  The last overload gave the following error.
    Argument of type '{ type: string; name: string; message: string; default: string; }[]' is not assignable
 to parameter of type 'Readonly<DistributiveMerge<NumberConfig | InputConfig |

{ message: string; choices: readonly (Separator | Choice<unknown>)[]; pageSize?: number | undefined; loop?: 
boolean | undefined; default?: unknown; theme?: { ...; } | undefined; } | ... 5 more ... | EditorConfig, { ...; }>>'.

what is the issue here?

recursivezero avatar Aug 27 '24 16:08 recursivezero

have had same issue all day

beakae avatar Aug 27 '24 23:08 beakae

Also having this problem. Using node v18.19.0 and TypeScript.

zigzagoon1 avatar Aug 28 '24 02:08 zigzagoon1

Does it work like this?

const questions = [
  { type: "input", name: "packageName", message: "tell me package name", default: "template" }] as const;

I think what happen is you're sending a type that's too liberal to inquirer, and this then prevents any inference of the return type.

The core of the issue with the type you pass in is that type: string; is just invalid. type must be one of a few specific values.

Also, it'll work if you put it inline instead of assigning to a variable:

prompt([
  { type: "input", name: "packageName", message: "tell me package name", default: "template" }
]);

SBoudrias avatar Aug 30 '24 19:08 SBoudrias

Does it work like this?

const questions = [
  { type: "input", name: "packageName", message: "tell me package name", default: "template" }] as const;

I think what happen is you're sending a type that's too liberal to inquirer, and this then prevents any inference of the return type.

The core of the issue with the type you pass in is that type: string; is just invalid. type must be one of a few specific values.

Also, it'll work if you put it inline instead of assigning to a variable:

prompt([
  { type: "input", name: "packageName", message: "tell me package name", default: "template" }
]);

Not working for me.

beakae avatar Sep 02 '24 19:09 beakae

... so what's the error with that code?

SBoudrias avatar Sep 02 '24 19:09 SBoudrias

We released new core types today with [email protected]. Would appreciate people trying it out and bringing feedback - cheers!

SBoudrias avatar Sep 02 '24 22:09 SBoudrias