From 15862dbb37cad218767bcef26a95570c5a540211 Mon Sep 17 00:00:00 2001 From: RedGuy12 <61329810+RedGuy12@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:49:00 -0500 Subject: [PATCH 1/5] types: Use `ThreadChannel` and `AnyThreadChannel` consistently Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com> --- packages/discord.js/typings/index.d.ts | 54 +++++++++++---------- packages/discord.js/typings/index.test-d.ts | 12 ++++- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index aa96d1a9136b..fe73eda2918c 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -968,7 +968,7 @@ export abstract class BaseChannel extends Base { public get url(): string; public delete(): Promise; public fetch(force?: boolean): Promise; - public isThread(): this is AnyThreadChannel; + public isThread(): this is ThreadChannel; public isTextBased(): this is TextBasedChannel; public isDMBased(): this is PartialGroupDMChannel | DMChannel | PartialDMChannel; public isVoiceBased(): this is VoiceBasedChannel; @@ -2133,7 +2133,7 @@ export class Message extends Base { public removeAttachments(): Promise>; public reply(options: string | MessagePayload | MessageReplyOptions): Promise>; public resolveComponent(customId: string): MessageActionRowComponent | null; - public startThread(options: StartThreadOptions): Promise; + public startThread(options: StartThreadOptions): Promise>; public suppressEmbeds(suppress?: boolean): Promise>; public toJSON(): unknown; public toString(): string; @@ -3158,7 +3158,9 @@ export class TextChannel extends BaseGuildTextChannel { public type: ChannelType.GuildText; } -export type AnyThreadChannel = PublicThreadChannel | PrivateThreadChannel; +export type AnyThreadChannel = PublicThreadChannel | PrivateThreadChannel; +export type ForumThreadChannel = PublicThreadChannel; +export type TextThreadChannel = PublicThreadChannel | PrivateThreadChannel; export interface PublicThreadChannel extends ThreadChannel { type: ChannelType.PublicThread | ChannelType.AnnouncementThread; @@ -3207,9 +3209,9 @@ export class ThreadChannel extends BaseCha public type: ThreadChannelType; public get unarchivable(): boolean; public delete(reason?: string): Promise; - public edit(options: ThreadEditOptions): Promise; - public join(): Promise; - public leave(): Promise; + public edit(options: ThreadEditOptions): Promise; + public join(): Promise; + public leave(): Promise; public permissionsFor(memberOrRole: GuildMember | Role, checkAdmin?: boolean): Readonly; public permissionsFor( memberOrRole: GuildMemberResolvable | RoleResolvable, @@ -3217,18 +3219,15 @@ export class ThreadChannel extends BaseCha ): Readonly | null; public fetchOwner(options?: BaseFetchOptions): Promise; public fetchStarterMessage(options?: BaseFetchOptions): Promise | null>; - public setArchived(archived?: boolean, reason?: string): Promise; - public setAutoArchiveDuration( - autoArchiveDuration: ThreadAutoArchiveDuration, - reason?: string, - ): Promise; - public setInvitable(invitable?: boolean, reason?: string): Promise; - public setLocked(locked?: boolean, reason?: string): Promise; - public setName(name: string, reason?: string): Promise; + public setArchived(archived?: boolean, reason?: string): Promise; + public setAutoArchiveDuration(autoArchiveDuration: ThreadAutoArchiveDuration, reason?: string): Promise; + public setInvitable(invitable?: boolean, reason?: string): Promise; + public setLocked(locked?: boolean, reason?: string): Promise; + public setName(name: string, reason?: string): Promise; // The following 3 methods can only be run on forum threads. - public setAppliedTags(appliedTags: readonly Snowflake[], reason?: string): Promise>; - public pin(reason?: string): Promise>; - public unpin(reason?: string): Promise>; + public setAppliedTags(appliedTags: readonly Snowflake[], reason?: string): Promise>; + public pin(reason?: string): Promise>; + public unpin(reason?: string): Promise>; public toString(): ChannelMention; } @@ -4459,7 +4458,7 @@ export class StageInstanceManager extends CachedManager extends CachedManager< Snowflake, - ThreadChannel, + If, ThreadChannelResolvable > { protected constructor( @@ -4467,7 +4466,10 @@ export class ThreadManager extends CachedM iterable?: Iterable, ); public channel: If; - public fetch(options: ThreadChannelResolvable, cacheOptions?: BaseFetchOptions): Promise; + public fetch( + options: ThreadChannelResolvable, + cacheOptions?: BaseFetchOptions, + ): Promise | null>; public fetch( options: FetchThreadsOptions & { archived: FetchArchivedThreadOptions }, cacheOptions?: { cache?: boolean }, @@ -4478,11 +4480,13 @@ export class ThreadManager extends CachedM } export class GuildTextThreadManager extends ThreadManager { - public create(options: GuildTextThreadCreateOptions): Promise; + public create( + options: GuildTextThreadCreateOptions, + ): Promise>; } export class GuildForumThreadManager extends ThreadManager { - public create(options: GuildForumThreadCreateOptions): Promise; + public create(options: GuildForumThreadCreateOptions): Promise; } export class ThreadMemberManager extends CachedManager { @@ -4999,12 +5003,12 @@ export interface Caches { // TODO: GuildManager: [manager: typeof GuildManager, holds: typeof Guild]; GuildMemberManager: [manager: typeof GuildMemberManager, holds: typeof GuildMember]; GuildBanManager: [manager: typeof GuildBanManager, holds: typeof GuildBan]; - GuildForumThreadManager: [manager: typeof GuildForumThreadManager, holds: typeof ThreadChannel]; + GuildForumThreadManager: [manager: typeof GuildForumThreadManager, holds: ForumThreadChannel]; GuildInviteManager: [manager: typeof GuildInviteManager, holds: typeof Invite]; GuildMessageManager: [manager: typeof GuildMessageManager, holds: typeof Message]; GuildScheduledEventManager: [manager: typeof GuildScheduledEventManager, holds: typeof GuildScheduledEvent]; GuildStickerManager: [manager: typeof GuildStickerManager, holds: typeof Sticker]; - GuildTextThreadManager: [manager: typeof GuildTextThreadManager, holds: typeof ThreadChannel]; + GuildTextThreadManager: [manager: typeof GuildTextThreadManager, holds: TextThreadChannel]; MessageManager: [manager: typeof MessageManager, holds: typeof Message]; // TODO: PermissionOverwriteManager: [manager: typeof PermissionOverwriteManager, holds: typeof PermissionOverwrites]; PresenceManager: [manager: typeof PresenceManager, holds: typeof Presence]; @@ -5012,7 +5016,7 @@ export interface Caches { ReactionUserManager: [manager: typeof ReactionUserManager, holds: typeof User]; // TODO: RoleManager: [manager: typeof RoleManager, holds: typeof Role]; StageInstanceManager: [manager: typeof StageInstanceManager, holds: typeof StageInstance]; - ThreadManager: [manager: typeof ThreadManager, holds: typeof ThreadChannel]; + ThreadManager: [manager: typeof ThreadManager, holds: AnyThreadChannel]; ThreadMemberManager: [manager: typeof ThreadMemberManager, holds: typeof ThreadMember]; UserManager: [manager: typeof UserManager, holds: typeof User]; VoiceStateManager: [manager: typeof VoiceStateManager, holds: typeof VoiceState]; @@ -6679,7 +6683,7 @@ export type TextChannelResolvable = Snowflake | TextChannel; export type TextBasedChannelResolvable = Snowflake | TextBasedChannel; -export type ThreadChannelResolvable = AnyThreadChannel | Snowflake; +export type ThreadChannelResolvable = Snowflake | ThreadChannel; export type ThreadChannelType = ChannelType.AnnouncementThread | ChannelType.PublicThread | ChannelType.PrivateThread; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 980d9562872d..36e2533e7f6e 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -203,6 +203,8 @@ import { RoleSelectMenuComponent, ChannelSelectMenuComponent, MentionableSelectMenuComponent, + ForumThreadChannel, + TextThreadChannel, } from '.'; import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd'; import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders'; @@ -225,6 +227,10 @@ const client: Client = new Client({ maxSize: 200, keepOverLimit: member => member.id === client.user?.id, }, + ThreadManager: { + maxSize: 200, + keepOverLimit: value => !value.archived, + }, }), }); @@ -1624,8 +1630,10 @@ declare const guildChannelManager: GuildChannelManager; declare const threadManager: ThreadManager; { - expectType>(threadManager.fetch('12345678901234567')); - expectType>(threadManager.fetch('12345678901234567', { cache: true, force: false })); + expectType>(threadManager.fetch('12345678901234567')); + expectType>( + threadManager.fetch('12345678901234567', { cache: true, force: false }), + ); expectType>(threadManager.fetch()); expectType>(threadManager.fetch({})); expectType>(threadManager.fetch({ archived: { limit: 4 } })); From 903117eee57ca23ccc21c44320e3d875e82a77e8 Mon Sep 17 00:00:00 2001 From: cobalt <61329810+RedGuy12@users.noreply.github.com> Date: Wed, 27 Mar 2024 13:26:23 -0500 Subject: [PATCH 2/5] types: use union in typeguard Signed-off-by: cobalt <61329810+RedGuy12@users.noreply.github.com> --- packages/discord.js/typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index fe73eda2918c..4e4a00b70a37 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -968,7 +968,7 @@ export abstract class BaseChannel extends Base { public get url(): string; public delete(): Promise; public fetch(force?: boolean): Promise; - public isThread(): this is ThreadChannel; + public isThread(): this is AnyThreadChannel; public isTextBased(): this is TextBasedChannel; public isDMBased(): this is PartialGroupDMChannel | DMChannel | PartialDMChannel; public isVoiceBased(): this is VoiceBasedChannel; From b82ed0242d679eaad1ace18339b3ab69ec7b8ef1 Mon Sep 17 00:00:00 2001 From: cobalt <61329810+RedGuy12@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:46:06 -0500 Subject: [PATCH 3/5] types: update `AnyThreadChannel` Signed-off-by: cobalt <61329810+RedGuy12@users.noreply.github.com> --- packages/discord.js/typings/index.d.ts | 2 +- packages/discord.js/typings/index.test-d.ts | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 4e4a00b70a37..5386459e2010 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -3158,9 +3158,9 @@ export class TextChannel extends BaseGuildTextChannel { public type: ChannelType.GuildText; } -export type AnyThreadChannel = PublicThreadChannel | PrivateThreadChannel; export type ForumThreadChannel = PublicThreadChannel; export type TextThreadChannel = PublicThreadChannel | PrivateThreadChannel; +export type AnyThreadChannel = TextThreadChannel | ForumThreadChannel; export interface PublicThreadChannel extends ThreadChannel { type: ChannelType.PublicThread | ChannelType.AnnouncementThread; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 36e2533e7f6e..f87dea0baf6b 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -203,8 +203,6 @@ import { RoleSelectMenuComponent, ChannelSelectMenuComponent, MentionableSelectMenuComponent, - ForumThreadChannel, - TextThreadChannel, } from '.'; import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd'; import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders'; @@ -1630,10 +1628,8 @@ declare const guildChannelManager: GuildChannelManager; declare const threadManager: ThreadManager; { - expectType>(threadManager.fetch('12345678901234567')); - expectType>( - threadManager.fetch('12345678901234567', { cache: true, force: false }), - ); + expectType>(threadManager.fetch('12345678901234567')); + expectType>(threadManager.fetch('12345678901234567', { cache: true, force: false })); expectType>(threadManager.fetch()); expectType>(threadManager.fetch({})); expectType>(threadManager.fetch({ archived: { limit: 4 } })); From 140e23545f1deec2167c1cb7d43fe7ab550a3768 Mon Sep 17 00:00:00 2001 From: cobalt <61329810+RedGuy12@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:16:52 -0500 Subject: [PATCH 4/5] types: fix `CommandOptionResolver` tests Signed-off-by: cobalt <61329810+RedGuy12@users.noreply.github.com> --- packages/discord.js/typings/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 5386459e2010..2a3748b80ad4 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -6655,7 +6655,8 @@ export type Channel = | NewsChannel | StageChannel | TextChannel - | AnyThreadChannel + | PublicThreadChannel + | PrivateThreadChannel | VoiceChannel | ForumChannel | MediaChannel; From 3279d4df001a6c283081f4fc6f0d5baf473dd657 Mon Sep 17 00:00:00 2001 From: cobalt <61329810+RedGuy12@users.noreply.github.com> Date: Mon, 13 May 2024 17:04:41 -0500 Subject: [PATCH 5/5] types: revert caches changes Signed-off-by: cobalt <61329810+RedGuy12@users.noreply.github.com> --- packages/discord.js/typings/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 2a3748b80ad4..ebaec8c01436 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -5003,12 +5003,12 @@ export interface Caches { // TODO: GuildManager: [manager: typeof GuildManager, holds: typeof Guild]; GuildMemberManager: [manager: typeof GuildMemberManager, holds: typeof GuildMember]; GuildBanManager: [manager: typeof GuildBanManager, holds: typeof GuildBan]; - GuildForumThreadManager: [manager: typeof GuildForumThreadManager, holds: ForumThreadChannel]; + GuildForumThreadManager: [manager: typeof GuildForumThreadManager, holds: typeof ThreadChannel]; GuildInviteManager: [manager: typeof GuildInviteManager, holds: typeof Invite]; GuildMessageManager: [manager: typeof GuildMessageManager, holds: typeof Message]; GuildScheduledEventManager: [manager: typeof GuildScheduledEventManager, holds: typeof GuildScheduledEvent]; GuildStickerManager: [manager: typeof GuildStickerManager, holds: typeof Sticker]; - GuildTextThreadManager: [manager: typeof GuildTextThreadManager, holds: TextThreadChannel]; + GuildTextThreadManager: [manager: typeof GuildTextThreadManager, holds: typeof ThreadChannel]; MessageManager: [manager: typeof MessageManager, holds: typeof Message]; // TODO: PermissionOverwriteManager: [manager: typeof PermissionOverwriteManager, holds: typeof PermissionOverwrites]; PresenceManager: [manager: typeof PresenceManager, holds: typeof Presence]; @@ -5016,7 +5016,7 @@ export interface Caches { ReactionUserManager: [manager: typeof ReactionUserManager, holds: typeof User]; // TODO: RoleManager: [manager: typeof RoleManager, holds: typeof Role]; StageInstanceManager: [manager: typeof StageInstanceManager, holds: typeof StageInstance]; - ThreadManager: [manager: typeof ThreadManager, holds: AnyThreadChannel]; + 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];