Inquirer.prompt调用出现No Overload matches this call错误求助
问题原因及修复方案
问题原因
你遇到的“No Overload matches this call”错误,核心原因是Inquirer的TypeScript类型定义要求prompt方法的参数为问题对象数组,而非单个问题对象。虽然运行时单个对象能正常工作,但TypeScript会严格匹配方法的重载签名,因此触发了类型校验错误。
修复方法
最规范且稳妥的修复方式是将单个问题对象包裹在数组中,完全符合类型定义要求:
import inquirer from "inquirer"; import chalk from "chalk"; let answers = await inquirer.prompt([{ name: "age", type: "number", message: "Enter your Age:" }]);
如果确实需要传递单个问题对象(不推荐,不符合官方类型规范),可以通过类型断言临时绕过检查,但这种方式可能隐藏其他潜在类型问题:
import inquirer from "inquirer"; import chalk from "chalk"; import type { Question } from "inquirer"; let answers = await inquirer.prompt({ name: "age", type: "number", message: "Enter your Age:" } as Question);
内容的提问来源于stack exchange,提问作者SamsungZee
相关产品推荐
相关产品推荐

