feat: makeDeepPartial type

This commit is contained in:
MARCROCK22 2024-09-09 02:49:16 +00:00
parent 3374252a36
commit 751f9cedb2
3 changed files with 15 additions and 8 deletions

View File

@ -116,8 +116,8 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
compress: this.options?.gateway?.compress,
resharding: {
getInfo: () => this.proxy.gateway.bot.get(),
interval: this.options?.resharding?.interval as number,
percentage: this.options?.resharding?.percentage as number,
interval: this.options?.resharding?.interval,
percentage: this.options?.resharding?.percentage,
reloadGuilds: ids => {
this.__handleGuilds = this.__handleGuilds?.concat(ids) ?? ids;
},

View File

@ -16,12 +16,18 @@ export type StringToNumber<T extends string> = T extends `${infer N extends numb
export type MakePartial<T, K extends keyof T> = Omit<T, K> & { [P in K]?: T[P] };
export type MakeDeepPartial<T, K extends keyof T> = Omit<T, K> & {
[P in K]?: DeepPartial<T[P]>;
};
export type DeepPartial<T> = {
[K in keyof T]?: T[K] extends Record<any, any>
? DeepPartial<T[K]>
: T[K] extends (infer I)[]
? DeepPartial<I>[]
: Partial<T[K]>;
[K in keyof T]?: T[K] extends (...args: any[]) => any
? T[K]
: T[K] extends Record<any, any>
? DeepPartial<T[K]>
: T[K] extends (infer I)[]
? DeepPartial<I>[]
: Partial<T[K]>;
};
export type OmitInsert<T, K extends keyof T, I> = I extends [] ? Omit<T, K> & I[number] : Omit<T, K> & I;

View File

@ -19,6 +19,7 @@ import { DynamicBucket } from '../structures';
import { ConnectQueue } from '../structures/timeout';
import { Shard } from './shard';
import type { ShardManagerOptions, WorkerData } from './shared';
import type { MakeDeepPartial } from '../../common/types/util';
let parentPort: import('node:worker_threads').MessagePort;
let workerData: WorkerData;
@ -28,7 +29,7 @@ export class ShardManager extends Map<number, Shard> {
options: MakeRequired<ShardManagerOptions, keyof typeof ShardManagerDefaults>;
debugger?: Logger;
constructor(options: ShardManagerOptions) {
constructor(options: MakeDeepPartial<ShardManagerOptions, 'resharding'>) {
super();
this.options = MergeOptions<ShardManager['options']>(
ShardManagerDefaults,