Skip to content

Commit 1789ccb

Browse files
authored
fix: fix eventModule typing for Discord events (#368)
1 parent 25c5891 commit 1789ccb

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/core/modules.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function commandModule(mod: InputCommand): Module {
2626
* The wrapper function to define event modules for sern
2727
* @param mod
2828
*/
29-
export function eventModule(mod: InputEvent): Module {
29+
export function eventModule<T extends keyof ClientEvents = keyof ClientEvents>(mod: InputEvent<T>): Module {
3030
const [onEvent, plugins] = partitionPlugins(mod.plugins);
3131
if(onEvent.length !== 0) throw Error("Event modules cannot have ControlPlugins");
3232
return { ...mod,
@@ -35,8 +35,9 @@ export function eventModule(mod: InputEvent): Module {
3535
}
3636

3737
/** Create event modules from discord.js client events,
38-
* This is an {@link eventModule} for discord events,
39-
* where typings can be very bad.
38+
* This was an {@link eventModule} for discord events,
39+
* where typings were bad.
40+
* @deprecated Use {@link eventModule} instead
4041
* @param mod
4142
*/
4243
export function discordEvent<T extends keyof ClientEvents>(mod: {

src/types/core-modules.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ export interface CommandModuleDefs {
167167
[CommandType.Modal]: ModalSubmitCommand;
168168
}
169169

170-
export interface EventModuleDefs {
170+
export interface EventModuleDefs<T extends keyof ClientEvents = keyof ClientEvents> {
171171
[EventType.Sern]: SernEventCommand;
172-
[EventType.Discord]: DiscordEventCommand;
172+
[EventType.Discord]: DiscordEventCommand<T>;
173173
[EventType.External]: ExternalEventCommand;
174174
}
175175

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

193-
export type InputEvent = {
194-
[T in EventType]: EventModulesNoPlugins[T] & {
193+
export type InputEvent<K extends keyof ClientEvents = keyof ClientEvents> = {
194+
[T in EventType]: EventModulesNoPlugins<K>[T] & {
195195
once?: boolean;
196196
plugins?: InitPlugin[]
197197
};

0 commit comments

Comments
 (0)