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

types: bump @types/node version, use EventEmitter generic #10584

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion apps/guide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.5.2",
"@types/html-escaper": "^3.0.2",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@unocss/eslint-plugin": "^0.60.4",
Expand Down
2 changes: 1 addition & 1 deletion apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@tailwindcss/typography": "^0.5.13",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.5.2",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"undici": "6.19.8"
},
"devDependencies": {
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@vitest/coverage-v8": "^2.0.5",
"cross-env": "^7.0.3",
"eslint": "^8.57.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-extractor-model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"cross-env": "^7.0.3",
"eslint": "^8.57.0",
"eslint-config-neon": "^0.1.62",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-extractor-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@microsoft/tsdoc": "0.14.2"
},
"devDependencies": {
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"cross-env": "^7.0.3",
"eslint": "^8.57.0",
"eslint-config-neon": "^0.1.62",
Expand Down
2 changes: 1 addition & 1 deletion packages/api-extractor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.4",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@types/resolve": "^1.20.6",
"@types/semver": "^7.5.8",
"cpy-cli": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/brokers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^4.1.0",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@vitest/coverage-v8": "^2.0.5",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/builders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^4.1.0",
"@types/node": "^18.19.44",
"@types/node": "^18.19.62",
"@vitest/coverage-v8": "^2.0.5",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^4.1.0",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@vitest/coverage-v8": "^2.0.5",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^4.1.0",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@vitest/coverage-v8": "^2.0.5",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-discord-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",
"@favware/cliff-jumper": "^4.1.0",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@types/prompts": "^2.4.9",
"@types/validate-npm-package-name": "^4.0.2",
"@vitest/coverage-v8": "^2.0.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"devDependencies": {
"@sapphire/ts-config": "^5.0.1",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"eslint": "^8.57.0",
"eslint-config-neon": "^0.1.62",
"eslint-formatter-pretty": "^6.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"@discordjs/docgen": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^4.1.0",
"@types/node": "^16.18.105",
"@types/node": "^18.19.62",
"@typescript-eslint/eslint-plugin": "^8.2.0",
"@typescript-eslint/parser": "^8.2.0",
"cross-env": "^7.0.3",
Expand Down
92 changes: 14 additions & 78 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,10 @@ export abstract class Base {
public valueOf(): string;
}

export class BaseClient extends EventEmitter implements AsyncDisposable {
export class BaseClient<ClientEventMap extends Record<keyof ClientEventMap, unknown[]> = {}>
extends EventEmitter<ClientEventMap>
implements AsyncDisposable
{
public constructor(options?: ClientOptions | WebhookClientOptions);
private decrementMaxListeners(): void;
private incrementMaxListeners(): void;
Expand Down Expand Up @@ -949,7 +952,7 @@ export type If<Value extends boolean, TrueResult, FalseResult = null> = Value ex
? FalseResult
: TrueResult | FalseResult;

export class Client<Ready extends boolean = boolean> extends BaseClient {
export class Client<Ready extends boolean = boolean> extends BaseClient<ClientEvents> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a case for Client exposing its own type parameter here, for derived classes to be able to add their own mapped events?

public constructor(options: ClientOptions);
private actions: unknown;
private expectedGuilds: Set<Snowflake>;
Expand All @@ -967,18 +970,6 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
// This a technique used to brand the ready state. Or else we'll get `never` errors on typeguard checks.
private readonly _ready: Ready;

// Override inherited static EventEmitter methods, with added type checks for Client events.
public static once<Emitter extends EventEmitter, Event extends keyof ClientEvents>(
eventEmitter: Emitter,
eventName: Emitter extends Client ? Event : string | symbol,
options?: { signal?: AbortSignal | undefined },
): Promise<Emitter extends Client ? ClientEvents[Event] : any[]>;
public static on<Emitter extends EventEmitter, Event extends keyof ClientEvents>(
eventEmitter: Emitter,
eventName: Emitter extends Client ? Event : string | symbol,
options?: { signal?: AbortSignal | undefined },
): AsyncIterableIterator<Emitter extends Client ? ClientEvents[Event] : any[]>;

public application: If<Ready, ClientApplication>;
public channels: ChannelManager;
public get emojis(): BaseGuildEmojiManager;
Expand Down Expand Up @@ -1013,30 +1004,6 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
public login(token?: string): Promise<string>;
public isReady(): this is Client<true>;
public toJSON(): unknown;

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

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

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

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

public removeAllListeners<Event extends keyof ClientEvents>(event?: Event): this;
public removeAllListeners<Event extends string | symbol>(event?: Exclude<Event, keyof ClientEvents>): this;
}

export interface StickerPackFetchOptions {
Expand Down Expand Up @@ -1122,7 +1089,9 @@ export interface CollectorEventTypes<Key, Value, Extras extends unknown[] = []>
end: [collected: ReadonlyCollection<Key, Value>, reason: string];
}

export abstract class Collector<Key, Value, Extras extends unknown[] = []> extends EventEmitter {
export abstract class Collector<Key, Value, Extras extends unknown[] = []> extends EventEmitter<
CollectorEventTypes<Key, Value, Extras>
> {
protected constructor(client: Client<true>, options?: CollectorOptions<[Value, ...Extras]>);
private _timeout: NodeJS.Timeout | null;
private _idletimeout: NodeJS.Timeout | null;
Expand All @@ -1148,16 +1117,6 @@ export abstract class Collector<Key, Value, Extras extends unknown[] = []> exten
protected listener: (...args: any[]) => void;
public abstract collect(...args: unknown[]): Awaitable<Key | null>;
public abstract dispose(...args: unknown[]): Key | null;

public on<EventKey extends keyof CollectorEventTypes<Key, Value, Extras>>(
event: EventKey,
listener: (...args: CollectorEventTypes<Key, Value, Extras>[EventKey]) => void,
): this;

public once<EventKey extends keyof CollectorEventTypes<Key, Value, Extras>>(
event: EventKey,
listener: (...args: CollectorEventTypes<Key, Value, Extras>[EventKey]) => void,
): this;
}

export class ChatInputCommandInteraction<Cached extends CacheType = CacheType> extends CommandInteraction<Cached> {
Expand Down Expand Up @@ -1993,19 +1952,6 @@ export class InteractionCollector<Interaction extends CollectedInteraction> exte
public collect(interaction: Interaction): Snowflake;
public empty(): void;
public dispose(interaction: Interaction): Snowflake;
public on(event: 'collect' | 'dispose' | 'ignore', listener: (interaction: Interaction) => void): this;
public on(
event: 'end',
listener: (collected: ReadonlyCollection<Snowflake, Interaction>, reason: string) => void,
): this;
public on(event: string, listener: (...args: any[]) => void): this;

public once(event: 'collect' | 'dispose' | 'ignore', listener: (interaction: Interaction) => void): this;
public once(
event: 'end',
listener: (collected: ReadonlyCollection<Snowflake, Interaction>, reason: string) => void,
): this;
public once(event: string, listener: (...args: any[]) => void): this;
}

// tslint:disable-next-line no-empty-interface
Expand Down Expand Up @@ -2926,7 +2872,7 @@ export interface ShardEventTypes {
spawn: [process: ChildProcess | Worker];
}

export class Shard extends EventEmitter {
export class Shard extends EventEmitter<ShardEventTypes> {
private constructor(manager: ShardingManager, id: number);
private _evals: Map<string, Promise<unknown>>;
private _exitListener: (...args: any[]) => void;
Expand Down Expand Up @@ -2956,16 +2902,6 @@ export class Shard extends EventEmitter {
public respawn(options?: { delay?: number; timeout?: number }): Promise<ChildProcess>;
public send(message: unknown): Promise<Shard>;
public spawn(timeout?: number): Promise<ChildProcess>;

public on<Event extends keyof ShardEventTypes>(
event: Event,
listener: (...args: ShardEventTypes[Event]) => void,
): this;

public once<Event extends keyof ShardEventTypes>(
event: Event,
listener: (...args: ShardEventTypes[Event]) => void,
): this;
}

export class ShardClientUtil {
Expand Down Expand Up @@ -3002,7 +2938,11 @@ export class ShardClientUtil {
public static shardIdForGuildId(guildId: Snowflake, shardCount: number): number;
}

export class ShardingManager extends EventEmitter {
export interface ShardingManagerEventTypes {
shardCreate: [shard: Shard];
}

export class ShardingManager extends EventEmitter<ShardingManagerEventTypes> {
public constructor(file: string, options?: ShardingManagerOptions);
private _performOnShards(method: string, args: readonly unknown[]): Promise<unknown[]>;
private _performOnShards(method: string, args: readonly unknown[], shard: number): Promise<unknown>;
Expand Down Expand Up @@ -3034,10 +2974,6 @@ export class ShardingManager extends EventEmitter {
public fetchClientValues(prop: string, shard: number): Promise<unknown>;
public respawnAll(options?: MultipleShardRespawnOptions): Promise<Collection<number, Shard>>;
public spawn(options?: MultipleShardSpawnOptions): Promise<Collection<number, Shard>>;

public on(event: 'shardCreate', listener: (shard: Shard) => void): this;

public once(event: 'shardCreate', listener: (shard: Shard) => void): this;
}

export interface FetchRecommendedShardCountOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ client.on('guildCreate', async g => {

// EventEmitter static method overrides
expectType<Promise<[Client<true>]>>(Client.once(client, 'clientReady'));
expectType<AsyncIterableIterator<[Client<true>]>>(Client.on(client, 'clientReady'));
expectType<NodeJS.AsyncIterator<[client: Client<true>]>>(Client.on(client, 'clientReady'));

client.login('absolutely-valid-token');

Expand Down
2 changes: 1 addition & 1 deletion packages/docgen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"devDependencies": {
"@favware/cliff-jumper": "^4.1.0",
"@types/jsdoc-to-markdown": "^7.0.6",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"cross-env": "^7.0.3",
"eslint": "^8.57.0",
"eslint-config-neon": "^0.1.62",
Expand Down
2 changes: 1 addition & 1 deletion packages/formatters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^4.1.0",
"@types/node": "^16.18.105",
"@types/node": "^16.18.117",
"@vitest/coverage-v8": "^2.0.5",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^4.1.0",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@vitest/coverage-v8": "^2.0.5",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/proxy-container/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"tslib": "^2.6.3"
},
"devDependencies": {
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"cross-env": "^7.0.3",
"eslint": "^8.57.0",
"eslint-config-neon": "^0.1.62",
Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^4.1.0",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@types/supertest": "^6.0.2",
"@vitest/coverage-v8": "^2.0.5",
"cross-env": "^7.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
},
"devDependencies": {
"@turbo/gen": "^2.0.14",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@vitest/coverage-v8": "^2.0.5",
"cross-env": "^7.0.3",
"env-cmd": "^10.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",
"@favware/cliff-jumper": "^4.1.0",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@vitest/coverage-v8": "^2.0.5",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@storybook/react": "^8.1.5",
"@storybook/react-vite": "^8.1.5",
"@storybook/testing-library": "^0.2.2",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@unocss/eslint-plugin": "^0.60.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^4.1.0",
"@types/node": "^16.18.105",
"@types/node": "^16.18.117",
"@vitest/coverage-v8": "^2.0.5",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/voice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@discordjs/opus": "^0.9.0",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^4.1.0",
"@types/node": "18.19.45",
"@types/node": "18.19.62",
"@vitest/coverage-v8": "2.0.5",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"@discordjs/api-extractor": "workspace:^",
"@discordjs/scripts": "workspace:^",
"@favware/cliff-jumper": "^4.1.0",
"@types/node": "^18.19.45",
"@types/node": "^18.19.62",
"@vitest/coverage-v8": "^2.0.5",
"cross-env": "^7.0.3",
"esbuild-plugin-version-injector": "^1.2.1",
Expand Down
Loading