diff --git a/packages/discord.js/src/managers/CachedManager.js b/packages/discord.js/src/managers/CachedManager.js index 6a79597076e3..defa0c095461 100644 --- a/packages/discord.js/src/managers/CachedManager.js +++ b/packages/discord.js/src/managers/CachedManager.js @@ -22,11 +22,11 @@ class CachedManager extends DataManager { * @name CachedManager#_cache */ Object.defineProperty(this, '_cache', { - value: this.client.options.makeCache( - this.constructor[MakeCacheOverrideSymbol] ?? this.constructor, - this.holds, - this.constructor, - ), + value: this.client.options.makeCache({ + holds: this.holds, + manager: this.constructor, + managerType: this.constructor[MakeCacheOverrideSymbol] ?? this.constructor, + }), }); if (iterable) { diff --git a/packages/discord.js/src/util/Options.js b/packages/discord.js/src/util/Options.js index deeec8ea78dc..3c1746162fb5 100644 --- a/packages/discord.js/src/util/Options.js +++ b/packages/discord.js/src/util/Options.js @@ -5,12 +5,16 @@ const { DefaultWebSocketManagerOptions } = require('@discordjs/ws'); const { version } = require('../../package.json'); const { toSnakeCase } = require('./Transformers.js'); -// TODO(ckohen): switch order of params so full manager is first and "type" is optional +/** + * @typedef {Object} CacheFactoryParams + * @property {Function} holds The class that the cache will hold. + * @property {Function} manager The fully extended manager class the cache is being requested from. + * @property {Function} managerType The base manager class the cache is being requested from. + */ + /** * @typedef {Function} CacheFactory - * @param {Function} managerType The base manager class the cache is being requested from. - * @param {Function} holds The class that the cache will hold. - * @param {Function} manager The fully extended manager class the cache is being requested from. + * @param {CacheFactoryParams} params The parameters * @returns {Collection} A Collection used to store the cache of the manager. */ @@ -121,7 +125,7 @@ class Options extends null { const { Collection } = require('@discordjs/collection'); const { LimitedCollection } = require('./LimitedCollection.js'); - return (managerType, _, manager) => { + return ({ managerType, manager }) => { const setting = settings[manager.name] ?? settings[managerType.name]; /* eslint-disable-next-line eqeqeq */ if (setting == null) { diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index d687f05ee662..4e9f263bb8b1 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -5359,13 +5359,21 @@ export type OverriddenCaches = | 'GuildMessageManager' | 'GuildTextThreadManager'; +export interface CacheFactoryParams { + holds: Caches[Manager][1]; + manager: CacheConstructors[keyof Caches]; + managerType: CacheConstructors[Exclude]; +} + // This doesn't actually work the way it looks 😢. // Narrowing the type of `manager.name` doesn't propagate type information to `holds` and the return type. -export type CacheFactory = ( - managerType: CacheConstructors[Exclude], - holds: Caches[(typeof manager)['name']][1], - manager: CacheConstructors[keyof Caches], -) => (typeof manager)['prototype'] extends DataManager ? Collection : never; +export type CacheFactory = ({ + holds, + manager, + managerType, +}: CacheFactoryParams) => (typeof manager)['prototype'] extends DataManager + ? Collection + : never; export type CacheWithLimitsOptions = { [K in keyof Caches]?: Caches[K][0]['prototype'] extends DataManager