Skip to content

Commit

Permalink
fix: fix eventModule typing for Discord events (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
DuroCodes authored Aug 19, 2024
1 parent 25c5891 commit 1789ccb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/core/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function commandModule(mod: InputCommand): Module {
* The wrapper function to define event modules for sern
* @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);
if(onEvent.length !== 0) throw Error("Event modules cannot have ControlPlugins");
return { ...mod,
Expand All @@ -35,8 +35,9 @@ export function eventModule(mod: InputEvent): Module {
}

/** Create event modules from discord.js client events,
* This is an {@link eventModule} for discord events,
* where typings can be very bad.
* This was an {@link eventModule} for discord events,
* where typings were bad.
* @deprecated Use {@link eventModule} instead
* @param mod
*/
export function discordEvent<T extends keyof ClientEvents>(mod: {
Expand Down
12 changes: 6 additions & 6 deletions src/types/core-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ export interface CommandModuleDefs {
[CommandType.Modal]: ModalSubmitCommand;
}

export interface EventModuleDefs {
export interface EventModuleDefs<T extends keyof ClientEvents = keyof ClientEvents> {
[EventType.Sern]: SernEventCommand;
[EventType.Discord]: DiscordEventCommand;
[EventType.Discord]: DiscordEventCommand<T>;
[EventType.External]: ExternalEventCommand;
}

Expand All @@ -186,12 +186,12 @@ export interface SernAutocompleteData
type CommandModuleNoPlugins = {
[T in CommandType]: Omit<CommandModuleDefs[T], 'plugins' | 'onEvent' | 'meta' | 'locals'>;
};
type EventModulesNoPlugins = {
[T in EventType]: Omit<EventModuleDefs[T], 'plugins' | 'onEvent' | 'meta' | 'locals'> ;
type EventModulesNoPlugins<K extends keyof ClientEvents = keyof ClientEvents> = {
[T in EventType]: Omit<EventModuleDefs<K>[T], 'plugins' | 'onEvent' | 'meta' | 'locals'> ;
};

export type InputEvent = {
[T in EventType]: EventModulesNoPlugins[T] & {
export type InputEvent<K extends keyof ClientEvents = keyof ClientEvents> = {
[T in EventType]: EventModulesNoPlugins<K>[T] & {
once?: boolean;
plugins?: InitPlugin[]
};
Expand Down

0 comments on commit 1789ccb

Please sign in to comment.