fix: return type of helpers plugin

This commit is contained in:
Skillz4Killz
2022-05-18 16:12:51 +00:00
committed by GitHub
parent 3f1c924b9c
commit 0258722f24
+7 -4
View File
@@ -21,7 +21,9 @@ import { fetchAndRetrieveMembers } from "./src/fetchAndRetrieveMembers.ts";
import { BotWithCache } from "../cache/src/addCacheCollections.ts";
import { sendTextMessage } from "./src/sendTextMessage.ts";
export interface BotWithHelpersPlugin extends Bot {
export type BotWithHelpersPlugin<B extends Bot = Bot> = Omit<B, "helpers"> & HelperFunctionsFromHelperPlugin;
export interface HelperFunctionsFromHelperPlugin {
helpers: FinalHelpers & {
fetchAndRetrieveMembers: (
guildId: bigint,
@@ -72,8 +74,9 @@ export interface BotWithHelpersPlugin extends Bot {
};
}
export function enableHelpersPlugin(rawBot: Bot): BotWithHelpersPlugin {
const bot = rawBot as BotWithHelpersPlugin;
export function enableHelpersPlugin<B extends Bot = Bot>(rawBot: B): BotWithHelpersPlugin<B> {
// FORCE OVERRIDE THE TYPE SO WE CAN SETUP FUNCTIONS
const bot = rawBot as unknown as BotWithHelpersPlugin;
bot.helpers.fetchAndRetrieveMembers = (
guildId: bigint,
@@ -113,7 +116,7 @@ export function enableHelpersPlugin(rawBot: Bot): BotWithHelpersPlugin {
channelId: bigint,
) => moveMember(bot, guildId, memberId, channelId);
return bot as BotWithHelpersPlugin;
return bot as BotWithHelpersPlugin<B>;
}
// EXPORT EVERYTHING HERE SO USERS CAN OPT TO USE FUNCTIONS DIRECTLY