在我的第3方库中,我希望能够使用我自己的属性对其进行扩展并使用安全性。但是我似乎无法将这种类型扩展为包括我的自定义变量。希望当您看到示例时更有意义。
import * as discord from "discord.js";
import Settings from '../models/settings.model';
export default class Guild extends discord.Guild {
constructor(client: discord.Client, guilds: any, msg: discord.Message, settings: Settings) {
super(client, msg); //discord.Guild requires these in its constructor
//These are the values that I want to be a part of discord.Guild
guilds[msg.guild.id] = {
queue: [],
queueNames: [{}],
songDuration: null,
isPlaying: false,
dispatcher: null,
voiceChannel: null,
skipRequest: 0,
skipList: [],
botChannel: settings.bot_channel || null,
botRole: settings.bot_role || null,
adminRole: settings.bot_role || null,
prefix: settings.prefix || null,
oldPrefix: null
};
}
}
然后我希望能够像这样使用它:
customFunction(guild: discord.Guild, name: string){
guild.queue = [];
guild.songDuration = 23;
guild.isPlaying = true;
guild.dispatcher: null;
guild.DefaultPropertyWhichIsPartOfLibrary = someValue;
}
但是现在,guild.queue
是discord.Guild
的未知属性。我如何扩展此类型,使其知道它是discord.Guild
的一部分?