From 1d66e02d4499bb58667a6151efac1035b0cc4e16 Mon Sep 17 00:00:00 2001 From: Danial Raza Date: Mon, 14 Oct 2024 19:10:18 +0200 Subject: [PATCH] types: fix fetch options types --- packages/discord.js/src/index.js | 2 ++ .../src/managers/SubscriptionManager.js | 17 +++++++++++------ packages/discord.js/typings/index.d.ts | 15 ++++++++------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/discord.js/src/index.js b/packages/discord.js/src/index.js index cdedc8aa45c0..95cdfbb22491 100644 --- a/packages/discord.js/src/index.js +++ b/packages/discord.js/src/index.js @@ -83,6 +83,7 @@ exports.ReactionManager = require('./managers/ReactionManager'); exports.ReactionUserManager = require('./managers/ReactionUserManager'); exports.RoleManager = require('./managers/RoleManager'); exports.StageInstanceManager = require('./managers/StageInstanceManager'); +exports.SubscriptionManager = require('./managers/SubscriptionManager'); exports.ThreadManager = require('./managers/ThreadManager'); exports.ThreadMemberManager = require('./managers/ThreadMemberManager'); exports.UserManager = require('./managers/UserManager'); @@ -193,6 +194,7 @@ exports.SKU = require('./structures/SKU').SKU; exports.StringSelectMenuOptionBuilder = require('./structures/StringSelectMenuOptionBuilder'); exports.StageChannel = require('./structures/StageChannel'); exports.StageInstance = require('./structures/StageInstance').StageInstance; +exports.Subscription = require('./structures/Subscription'); exports.Sticker = require('./structures/Sticker').Sticker; exports.StickerPack = require('./structures/StickerPack'); exports.Team = require('./structures/Team'); diff --git a/packages/discord.js/src/managers/SubscriptionManager.js b/packages/discord.js/src/managers/SubscriptionManager.js index c29e9538c0fa..ea25b9b858a5 100644 --- a/packages/discord.js/src/managers/SubscriptionManager.js +++ b/packages/discord.js/src/managers/SubscriptionManager.js @@ -23,28 +23,33 @@ class SubscriptionManager extends CachedManager { * @name SubscriptionManager#cache */ + /** + * Options used to fetch a subscription + * @typedef {BaseFetchOptions} FetchSubscriptionOptions + * @property {SKUResolvable} sku The SKU to fetch the subscription for + * @property {Snowflake} subscriptionId The id of the subscription to fetch + */ + /** * Options used to fetch subscriptions * @typedef {Object} FetchSubscriptionsOptions + * @property {Snowflake} [after] Consider only subscriptions after this subscription id + * @property {Snowflake} [before] Consider only subscriptions before this subscription id * @property {number} [limit=50] The maximum number of subscriptions to fetch * @property {SKUResolvable} sku The SKU to fetch subscriptions for - * @property {Snowflake} [subscriptionId] The subscription id to fetch * @property {UserResolvable} user The user to fetch entitlements for - * @property {boolean} [cache=true] Whether to cache the fetched subscriptions - * @property {Snowflake} [before] Consider only subscriptions before this subscription id - * @property {Snowflake} [after] Consider only subscriptions after this subscription id * If both `before` and `after` are provided, only `before` is respected */ /** * Fetches subscriptions for this application - * @param {FetchSubscriptionsOptions} [options={}] Options for fetching the subscriptions + * @param {FetchSubscriptionOptions|FetchSubscriptionsOptions} [options={}] Options for fetching the subscriptions * @returns {Promise>} */ async fetch(options = {}) { if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true); - const { limit = 50, sku, subscriptionId, user, cache = true, before, after } = options; + const { after, before, cache = true, limit = 50, sku, subscriptionId, user } = options; const skuId = resolveSKUId(sku); diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 22792bd83d37..367ddb06ed4f 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -4094,22 +4094,23 @@ export class EntitlementManager extends CachedManager; } +export interface FetchSubscriptionOptions extends BaseFetchOptions { + sku: SKUResolvable; + subscriptionId: Snowflake; +} + export interface FetchSubscriptionsOptions { + after?: Snowflake; + before?: Snowflake; limit?: number; sku: SKUResolvable; - subscriptionId?: undefined; user: UserResolvable; - cache?: boolean; - before?: Snowflake; - after?: Snowflake; } export class SubscriptionManager extends CachedManager { private constructor(client: Client, iterable?: Iterable); + public fetch(options: FetchSubscriptionOptions): Promise; public fetch(options: FetchSubscriptionsOptions): Promise>; - public fetch( - options: Omit & { subscriptionId: Snowflake }, - ): Promise; } export interface FetchGuildApplicationCommandFetchOptions extends Omit {}