fix: fix eventModule typing for Discord events (#368)

This commit is contained in:
Duro
2024-08-19 12:18:13 -04:00
committed by GitHub
parent 25c5891ade
commit 1789ccb2f2
2 changed files with 10 additions and 9 deletions

View File

@@ -26,7 +26,7 @@ export function commandModule(mod: InputCommand): Module {
* The wrapper function to define event modules for sern * The wrapper function to define event modules for sern
* @param mod * @param mod
*/ */
export function eventModule(mod: InputEvent): Module { export function eventModule<T extends keyof ClientEvents = keyof ClientEvents>(mod: InputEvent<T>): Module {
const [onEvent, plugins] = partitionPlugins(mod.plugins); const [onEvent, plugins] = partitionPlugins(mod.plugins);
if(onEvent.length !== 0) throw Error("Event modules cannot have ControlPlugins"); if(onEvent.length !== 0) throw Error("Event modules cannot have ControlPlugins");
return { ...mod, return { ...mod,
@@ -35,8 +35,9 @@ export function eventModule(mod: InputEvent): Module {
} }
/** Create event modules from discord.js client events, /** Create event modules from discord.js client events,
* This is an {@link eventModule} for discord events, * This was an {@link eventModule} for discord events,
* where typings can be very bad. * where typings were bad.
* @deprecated Use {@link eventModule} instead
* @param mod * @param mod
*/ */
export function discordEvent<T extends keyof ClientEvents>(mod: { export function discordEvent<T extends keyof ClientEvents>(mod: {

View File

@@ -167,9 +167,9 @@ export interface CommandModuleDefs {
[CommandType.Modal]: ModalSubmitCommand; [CommandType.Modal]: ModalSubmitCommand;
} }
export interface EventModuleDefs { export interface EventModuleDefs<T extends keyof ClientEvents = keyof ClientEvents> {
[EventType.Sern]: SernEventCommand; [EventType.Sern]: SernEventCommand;
[EventType.Discord]: DiscordEventCommand; [EventType.Discord]: DiscordEventCommand<T>;
[EventType.External]: ExternalEventCommand; [EventType.External]: ExternalEventCommand;
} }
@@ -186,12 +186,12 @@ export interface SernAutocompleteData
type CommandModuleNoPlugins = { type CommandModuleNoPlugins = {
[T in CommandType]: Omit<CommandModuleDefs[T], 'plugins' | 'onEvent' | 'meta' | 'locals'>; [T in CommandType]: Omit<CommandModuleDefs[T], 'plugins' | 'onEvent' | 'meta' | 'locals'>;
}; };
type EventModulesNoPlugins = { type EventModulesNoPlugins<K extends keyof ClientEvents = keyof ClientEvents> = {
[T in EventType]: Omit<EventModuleDefs[T], 'plugins' | 'onEvent' | 'meta' | 'locals'> ; [T in EventType]: Omit<EventModuleDefs<K>[T], 'plugins' | 'onEvent' | 'meta' | 'locals'> ;
}; };
export type InputEvent = { export type InputEvent<K extends keyof ClientEvents = keyof ClientEvents> = {
[T in EventType]: EventModulesNoPlugins[T] & { [T in EventType]: EventModulesNoPlugins<K>[T] & {
once?: boolean; once?: boolean;
plugins?: InitPlugin[] plugins?: InitPlugin[]
}; };