Skip to content

Commit

Permalink
feat: makeDeepPartial type
Browse files Browse the repository at this point in the history
  • Loading branch information
MARCROCK22 committed Sep 9, 2024
1 parent 3374252 commit 751f9ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
16 changes: 11 additions & 5 deletions src/common/types/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/websocket/discord/sharder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 751f9ce

Please sign in to comment.