fix(Sharding): strict type context and return (#5933)

This commit is contained in:
Antonio Román
2021-06-29 21:36:04 +02:00
committed by GitHub
parent 87e8cdd3eb
commit 1925d01d8f
2 changed files with 80 additions and 12 deletions

40
typings/index.d.ts vendored
View File

@@ -150,7 +150,7 @@ declare enum WebhookTypes {
'Channel Follower' = 2,
}
type Awaited<T> = T | Promise<T>;
type Awaited<T> = T | PromiseLike<T>;
declare module '@discordjs/voice' {
import { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData } from 'discord-api-types/v8';
@@ -1793,13 +1793,16 @@ declare module 'discord.js' {
public readonly ids: number[];
public mode: ShardingManagerMode;
public parentPort: any | null;
public broadcastEval<T>(fn: (client: Client) => T): Promise<T[]>;
public broadcastEval<T>(fn: (client: Client) => T, options: { shard: number }): Promise<T>;
public broadcastEval<T, P>(fn: (client: Client, context: P) => T, options: { context: P }): Promise<T[]>;
public broadcastEval<T>(fn: (client: Client) => Awaited<T>): Promise<Serialized<T>[]>;
public broadcastEval<T>(fn: (client: Client) => Awaited<T>, options: { shard: number }): Promise<Serialized<T>>;
public broadcastEval<T, P>(
fn: (client: Client, context: P) => T,
fn: (client: Client, context: Serialized<P>) => Awaited<T>,
options: { context: P },
): Promise<Serialized<T>[]>;
public broadcastEval<T, P>(
fn: (client: Client, context: Serialized<P>) => Awaited<T>,
options: { context: P; shard: number },
): Promise<T>;
): Promise<Serialized<T>>;
public fetchClientValues(prop: string): Promise<any[]>;
public fetchClientValues(prop: string, shard: number): Promise<any>;
public respawnAll(options?: MultipleShardRespawnOptions): Promise<void>;
@@ -1822,13 +1825,16 @@ declare module 'discord.js' {
public totalShards: number | 'auto';
public shardList: number[] | 'auto';
public broadcast(message: any): Promise<Shard[]>;
public broadcastEval<T>(fn: (client: Client) => T): Promise<T[]>;
public broadcastEval<T>(fn: (client: Client) => T, options: { shard: number }): Promise<T>;
public broadcastEval<T, P>(fn: (client: Client, context: P) => T, options: { context: P }): Promise<T[]>;
public broadcastEval<T>(fn: (client: Client) => Awaited<T>): Promise<Serialized<T>[]>;
public broadcastEval<T>(fn: (client: Client) => Awaited<T>, options: { shard: number }): Promise<Serialized<T>>;
public broadcastEval<T, P>(
fn: (client: Client, context: P) => T,
fn: (client: Client, context: Serialized<P>) => Awaited<T>,
options: { context: P },
): Promise<Serialized<T>[]>;
public broadcastEval<T, P>(
fn: (client: Client, context: Serialized<P>) => Awaited<T>,
options: { context: P; shard: number },
): Promise<T>;
): Promise<Serialized<T>>;
public createShard(id: number): Shard;
public fetchClientValues(prop: string): Promise<any[]>;
public fetchClientValues(prop: string, shard: number): Promise<any>;
@@ -4408,5 +4414,17 @@ declare module 'discord.js' {
| 'STAGE_INSTANCE_UPDATE'
| 'STAGE_INSTANCE_DELETE';
type Serialized<T> = T extends symbol | bigint | (() => unknown)
? never
: T extends number | string | boolean | undefined
? T
: T extends { toJSON(): infer R }
? R
: T extends ReadonlyArray<infer V>
? Serialized<V>[]
: T extends ReadonlyMap<unknown, unknown> | ReadonlySet<unknown>
? {}
: { [K in keyof T]: Serialized<T[K]> };
//#endregion
}