You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 18:52:01