types(Options): add types for cacheWithLimits (#6095)

This commit is contained in:
DTrombett
2021-07-16 13:20:38 +02:00
committed by GitHub
parent 576eee8de2
commit 8db6df3d1e
3 changed files with 35 additions and 5 deletions

33
typings/index.d.ts vendored
View File

@@ -366,7 +366,7 @@ export class ClientUser extends User {
export class Options extends null {
private constructor();
public static createDefaultOptions(): ClientOptions;
public static cacheWithLimits(limits?: Record<string, number>): CacheFactory;
public static cacheWithLimits(limits?: CacheWithLimitOptions): CacheFactory;
public static cacheEverything(): CacheFactory;
}
@@ -2739,7 +2739,36 @@ export type BitFieldResolvable<T extends string, N extends number | bigint> =
export type BufferResolvable = Buffer | string;
export type CacheFactory = <T>(manager: { name: string }, holds: { name: string }) => Collection<Snowflake, T>;
export type CachedManagerTypes = keyof CacheFactoryArgs;
export type CacheFactory = <T extends CachedManagerTypes>(
...args: CacheFactoryArgs[T]
) => Collection<Snowflake, CacheFactoryArgs[T][1]>;
export interface CacheFactoryArgs {
ApplicationCommandManager: [manager: typeof ApplicationCommandManager, holds: typeof ApplicationCommand];
BaseGuildEmojiManager: [manager: typeof BaseGuildEmojiManager, holds: typeof GuildEmoji];
ChannelManager: [manager: typeof ChannelManager, holds: typeof Channel];
GuildChannelManager: [manager: typeof GuildChannelManager, holds: typeof GuildChannel];
GuildManager: [manager: typeof GuildManager, holds: typeof Guild];
GuildMemberManager: [manager: typeof GuildMemberManager, holds: typeof GuildMember];
GuildBanManager: [manager: typeof GuildBanManager, holds: typeof GuildBan];
MessageManager: [manager: typeof MessageManager, holds: typeof Message];
PermissionOverwriteManager: [manager: typeof PermissionOverwriteManager, holds: typeof PermissionOverwrites];
PresenceManager: [manager: typeof PresenceManager, holds: typeof Presence];
ReactionManager: [manager: typeof ReactionManager, holds: typeof MessageReaction];
ReactionUserManager: [manager: typeof ReactionUserManager, holds: typeof User];
RoleManager: [manager: typeof RoleManager, holds: typeof Role];
StageInstanceManager: [manager: typeof StageInstanceManager, holds: typeof StageInstance];
ThreadManager: [manager: typeof ThreadManager, holds: typeof ThreadChannel];
ThreadMemberManager: [manager: typeof ThreadMemberManager, holds: typeof ThreadMember];
UserManager: [manager: typeof UserManager, holds: typeof User];
VoiceStateManager: [manager: typeof VoiceStateManager, holds: typeof VoiceState];
}
export type CacheWithLimitOptions = {
[K in CachedManagerTypes]?: number;
};
export interface ChannelCreationOverwrites {
allow?: PermissionResolvable;

View File

@@ -53,6 +53,8 @@ const client: Client = new Client({
intents: Intents.FLAGS.GUILDS,
makeCache: Options.cacheWithLimits({
MessageManager: 200,
// @ts-expect-error
Message: 100,
}),
});