简体   繁体   English

数据类型的属性不存在

[英]Properties do not exist for data type

I am new to TypeScript and I am having two problems with data types.我是 TypeScript 的新手,我在数据类型方面遇到了两个问题。

This is my code:这是我的代码:

const say: object = {
  name: "say",
  aliases: [""],
  description: "",
  usage: "",
  run: (client: object, msg: object, args: string) => {
    if (!args[0]) return;
    msg.channel.send(args.join(" "));
  },
};

export default say;

The errors that come out are:出现的错误是:

Property 'channel' does not exist on type 'object'. “对象”类型上不存在属性“通道”。

Property 'join' does not exist on type 'string'. “字符串”类型上不存在属性“加入”。

I did a console.log (typeof msg) and console.log (typeof args) and indeed its data type is object and string .我做了一个console.log (typeof msg)console.log (typeof args)并且它的数据类型确实是objectstring

I'm looking for an alternative to change the data type to any .我正在寻找将数据类型更改为any的替代方法。

I assume that channel and message are discord.js types.我假设channelmessagediscord.js类型。 So you can check discord.js types from here: https://github.com/discordjs/discord.js/tree/master/typings所以你可以从这里检查 discord.js 类型: https://github.com/discordjs/discord.js/tree/master/typings

and you can use Message type like this:你可以像这样使用消息类型:

import {Message }from "discord.js"

in the second question.在第二个问题。 join is not a property for string. join 不是字符串的属性。 it's the property for arrays so probably args would be string[]它是 arrays 的属性,所以 args 可能是string[]

If you are sure about the type of msg, then you can create your own type.如果您确定 msg 的类型,那么您可以创建自己的类型。

interface Msg {
    channel: type here;
}
at the run, use this interface. (client: object, msg: Msg, args: string)

if you are not sure about its structure, then just say 'msg' there without any typedef.如果您不确定它的结构,那么只需在此处说“msg”而不使用任何 typedef。

do you mean args: string[] .你的意思是args: string[] It doesn't make sense to apply a join on a string here.在这里对字符串应用连接是没有意义的。

暂无
暂无

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

相关问题 Object 字面量只能指定已知属性,并且“PromiseLike”类型中不存在“数据”<t> '</t> - Object literal may only specify known properties, and 'data' does not exist in type 'PromiseLike<T>' 角度2中的类型“ {}”上似乎不存在属性“目标”和“长度”吗? - The properties “target” and “length” doesn't seem to exist on type “{}” in angular 2? 对象字面量只能指定已知属性,并且“模块”类型不存在于“模块元数据”类型中 - Object literal may only specify known properties, and 'modules' does not exist in type 'ModuleMetadata' TypeScript错误:对象文字只能指定已知属性,并且“DeepPartial”类型中不存在“...” <Document> “ - TypeScript Error: Object literal may only specify known properties, and '…' does not exist in type 'DeepPartial<Document>' firebase函数属性“数据”在类型“更改”上不存在 <DataSnapshot> &#39; - firebase functions Property 'data' does not exist on type 'Change<DataSnapshot>' Express 和 Typescript - Error.stack 和 Error.status 属性不存在 - Express and Typescript - Error.stack and Error.status properties do not exist 在mongodb上存储数据之前,需要检查用户名和电子邮件是否确实存在 - Need to check username and email do exist before storing data on mongodb 如何搜索具有多个属性的猫鼬数据? - How do I search the mongoose data with with multiple properties? 类型 object 上不存在属性 - Property does not exist on type object 属性“”在类型“对象”上不存在 - Property '' does not exist on type 'Object'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM