Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix eventModule typing for Discord events #368

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
jacoobes marked this conversation as resolved.
Show resolved Hide resolved
* @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
Loading