Skip to content

Commit

Permalink
fix(Types): make event listeners accept async callbacks (#5602)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet committed May 29, 2021
1 parent add924c commit a73a5cf
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions typings/index.d.ts
Expand Up @@ -55,6 +55,8 @@ declare enum StickerFormatTypes {
LOTTIE = 3,
}

type Awaited<T> = T | Promise<T>;

declare module 'discord.js' {
import BaseCollection from '@discordjs/collection';
import { ChildProcess } from 'child_process';
Expand Down Expand Up @@ -325,25 +327,25 @@ declare module 'discord.js' {
public sweepMessages(lifetime?: number): number;
public toJSON(): object;

public on<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => void): this;
public on<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => Awaited<void>): this;
public on<S extends string | symbol>(
event: Exclude<S, keyof ClientEvents>,
listener: (...args: any[]) => void,
listener: (...args: any[]) => Awaited<void>,
): this;

public once<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => void): this;
public once<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => Awaited<void>): this;
public once<S extends string | symbol>(
event: Exclude<S, keyof ClientEvents>,
listener: (...args: any[]) => void,
listener: (...args: any[]) => Awaited<void>,
): this;

public emit<K extends keyof ClientEvents>(event: K, ...args: ClientEvents[K]): boolean;
public emit<S extends string | symbol>(event: Exclude<S, keyof ClientEvents>, ...args: any[]): boolean;

public off<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => void): this;
public off<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => Awaited<void>): this;
public off<S extends string | symbol>(
event: Exclude<S, keyof ClientEvents>,
listener: (...args: any[]) => void,
listener: (...args: any[]) => Awaited<void>,
): this;

public removeAllListeners<K extends keyof ClientEvents>(event?: K): this;
Expand Down

0 comments on commit a73a5cf

Please sign in to comment.