简体   繁体   English

TypeError [ERR_INVALID_ARG_TYPE]:“id”参数必须是字符串类型

[英]TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string

I'm working on an NPM package to make a command handler for Discord.我正在研究 NPM package 来为 Discord 创建一个命令处理程序。 I get the following error:我收到以下错误:

(node:9400) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received undefined.

这是错误的

he error says that is in line:他的错误说这是一致的:

switch (_f.label) {

I tried all but I dont have a solution我尝试了所有但我没有解决方案

The value in the switch statement should be of the same type as the values in the case statements. switch语句中的值应与case语句中的值具有相同的类型。

In your sample, the value in switch is a string , and the cases are number s.在您的示例中, switch中的值是string ,而 case 是number

Make them all of the same type:使它们都具有相同的类型:

switch(parseInt(label)) {

or或者

case "0":
case "1":
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 收到未定义和代码:'ERR_INVALID_ARG_TYPE' - TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined and code: 'ERR_INVALID_ARG_TYPE' 类型错误 [ERR_INVALID_ARG_TYPE]:“文件”参数必须是字符串类型。 接收类型对象 - TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object [ERR_INVALID_ARG_TYPE]:“id”参数必须是字符串类型。 接收类型对象 - [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received type object TypeError [ERR_INVALID_ARG_TYPE]:“数据”参数必须是字符串类型或 Buffer、TypedArray 或 DataView 的实例 - TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型 Node.JS - TypeError [ERR_INVALID_ARG_TYPE]: The “path” argument must be of type string Node.JS TypeError [ERR_INVALID_ARG_TYPE]:“块”参数必须是字符串类型或 Buffer 或 Uint8Array 的实例 - TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 收到 Object 的实例 - TypeError [ERR_INVALID_ARG_TYPE]: The “path” argument must be of type string. Received an instance of Object 等待 dTypeError [ERR_INVALID_ARG_TYPE]:“id”参数必须是字符串类型。 收到未定义 - Waiting for the dTypeError [ERR_INVALID_ARG_TYPE]: The “id” argument must be of type string. Received undefined Webpack 类型错误'TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 接收类型布尔值(真)' - Webpack type error 'TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type boolean (true)' TypeError [ERR_INVALID_ARG_TYPE]:“块”参数必须是字符串或缓冲区类型之一。 接收型号 - TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be one of type string or Buffer. Received type number
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM