`createPromptModule` typing error : No overload matches this call. The last overload gave the following error.0
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?
have had same issue all day
Also having this problem. Using node v18.19.0 and TypeScript.
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" }
]);
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.typemust 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.
... so what's the error with that code?
We released new core types today with [email protected]. Would appreciate people trying it out and bringing feedback - cheers!