Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: Use ThreadChannel and AnyThreadChannel consistently #10181

Merged
merged 12 commits into from
Aug 20, 2024
55 changes: 30 additions & 25 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ export class Message<InGuild extends boolean = boolean> extends Base {
public removeAttachments(): Promise<Message<InGuild>>;
public reply(options: string | MessagePayload | MessageReplyOptions): Promise<Message<InGuild>>;
public resolveComponent(customId: string): MessageActionRowComponent | null;
public startThread(options: StartThreadOptions): Promise<AnyThreadChannel>;
public startThread(options: StartThreadOptions): Promise<PublicThreadChannel<false>>;
public suppressEmbeds(suppress?: boolean): Promise<Message<InGuild>>;
public toJSON(): unknown;
public toString(): string;
Expand Down Expand Up @@ -3158,7 +3158,9 @@ export class TextChannel extends BaseGuildTextChannel {
public type: ChannelType.GuildText;
}

export type AnyThreadChannel<Forum extends boolean = boolean> = PublicThreadChannel<Forum> | PrivateThreadChannel;
export type ForumThreadChannel = PublicThreadChannel<true>;
export type TextThreadChannel = PublicThreadChannel<false> | PrivateThreadChannel;
export type AnyThreadChannel = TextThreadChannel | ForumThreadChannel;

export interface PublicThreadChannel<Forum extends boolean = boolean> extends ThreadChannel<Forum> {
type: ChannelType.PublicThread | ChannelType.AnnouncementThread;
Expand Down Expand Up @@ -3207,28 +3209,25 @@ export class ThreadChannel<ThreadOnly extends boolean = boolean> extends BaseCha
public type: ThreadChannelType;
public get unarchivable(): boolean;
public delete(reason?: string): Promise<this>;
public edit(options: ThreadEditOptions): Promise<AnyThreadChannel>;
public join(): Promise<AnyThreadChannel>;
public leave(): Promise<AnyThreadChannel>;
public edit(options: ThreadEditOptions): Promise<this>;
public join(): Promise<this>;
public leave(): Promise<this>;
public permissionsFor(memberOrRole: GuildMember | Role, checkAdmin?: boolean): Readonly<PermissionsBitField>;
public permissionsFor(
memberOrRole: GuildMemberResolvable | RoleResolvable,
checkAdmin?: boolean,
): Readonly<PermissionsBitField> | null;
public fetchOwner(options?: BaseFetchOptions): Promise<ThreadMember | null>;
public fetchStarterMessage(options?: BaseFetchOptions): Promise<Message<true> | null>;
public setArchived(archived?: boolean, reason?: string): Promise<AnyThreadChannel>;
public setAutoArchiveDuration(
autoArchiveDuration: ThreadAutoArchiveDuration,
reason?: string,
): Promise<AnyThreadChannel>;
public setInvitable(invitable?: boolean, reason?: string): Promise<AnyThreadChannel>;
public setLocked(locked?: boolean, reason?: string): Promise<AnyThreadChannel>;
public setName(name: string, reason?: string): Promise<AnyThreadChannel>;
public setArchived(archived?: boolean, reason?: string): Promise<this>;
public setAutoArchiveDuration(autoArchiveDuration: ThreadAutoArchiveDuration, reason?: string): Promise<this>;
public setInvitable(invitable?: boolean, reason?: string): Promise<this>;
public setLocked(locked?: boolean, reason?: string): Promise<this>;
public setName(name: string, reason?: string): Promise<this>;
// The following 3 methods can only be run on forum threads.
public setAppliedTags(appliedTags: readonly Snowflake[], reason?: string): Promise<ThreadChannel<true>>;
public pin(reason?: string): Promise<ThreadChannel<true>>;
public unpin(reason?: string): Promise<ThreadChannel<true>>;
public setAppliedTags(appliedTags: readonly Snowflake[], reason?: string): Promise<If<ThreadOnly, this, never>>;
public pin(reason?: string): Promise<If<ThreadOnly, this, never>>;
public unpin(reason?: string): Promise<If<ThreadOnly, this, never>>;
vladfrangu marked this conversation as resolved.
Show resolved Hide resolved
public toString(): ChannelMention;
}

Expand Down Expand Up @@ -4459,15 +4458,18 @@ export class StageInstanceManager extends CachedManager<Snowflake, StageInstance

export class ThreadManager<ThreadOnly extends boolean = boolean> extends CachedManager<
Snowflake,
ThreadChannel<ThreadOnly>,
If<ThreadOnly, ForumThreadChannel, TextThreadChannel>,
ThreadChannelResolvable
> {
protected constructor(
channel: TextChannel | NewsChannel | ForumChannel | MediaChannel,
iterable?: Iterable<RawThreadChannelData>,
);
public channel: If<ThreadOnly, ForumChannel | MediaChannel, TextChannel | NewsChannel>;
public fetch(options: ThreadChannelResolvable, cacheOptions?: BaseFetchOptions): Promise<AnyThreadChannel | null>;
public fetch(
options: ThreadChannelResolvable,
cacheOptions?: BaseFetchOptions,
): Promise<If<ThreadOnly, ForumThreadChannel, TextThreadChannel> | null>;
public fetch(
options: FetchThreadsOptions & { archived: FetchArchivedThreadOptions },
cacheOptions?: { cache?: boolean },
Expand All @@ -4478,11 +4480,13 @@ export class ThreadManager<ThreadOnly extends boolean = boolean> extends CachedM
}

export class GuildTextThreadManager<AllowedThreadType> extends ThreadManager<false> {
public create(options: GuildTextThreadCreateOptions<AllowedThreadType>): Promise<ThreadChannel>;
public create(
options: GuildTextThreadCreateOptions<AllowedThreadType>,
): Promise<AllowedThreadType extends ChannelType.PrivateThread ? PrivateThreadChannel : PublicThreadChannel<false>>;
}

export class GuildForumThreadManager extends ThreadManager<true> {
public create(options: GuildForumThreadCreateOptions): Promise<ThreadChannel>;
public create(options: GuildForumThreadCreateOptions): Promise<ForumThreadChannel>;
}

export class ThreadMemberManager extends CachedManager<Snowflake, ThreadMember, ThreadMemberResolvable> {
Expand Down Expand Up @@ -5006,20 +5010,20 @@ 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<true>];
GuildForumThreadManager: [manager: typeof GuildForumThreadManager, holds: ForumThreadChannel];
GuildInviteManager: [manager: typeof GuildInviteManager, holds: typeof Invite];
GuildMessageManager: [manager: typeof GuildMessageManager, holds: typeof Message<true>];
GuildScheduledEventManager: [manager: typeof GuildScheduledEventManager, holds: typeof GuildScheduledEvent];
GuildStickerManager: [manager: typeof GuildStickerManager, holds: typeof Sticker];
GuildTextThreadManager: [manager: typeof GuildTextThreadManager, holds: typeof ThreadChannel<false>];
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];
ReactionManager: [manager: typeof ReactionManager, holds: typeof MessageReaction];
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];
cobaltt7 marked this conversation as resolved.
Show resolved Hide resolved
cobaltt7 marked this conversation as resolved.
Show resolved Hide resolved
ThreadMemberManager: [manager: typeof ThreadMemberManager, holds: typeof ThreadMember];
UserManager: [manager: typeof UserManager, holds: typeof User];
VoiceStateManager: [manager: typeof VoiceStateManager, holds: typeof VoiceState];
Expand Down Expand Up @@ -6646,7 +6650,8 @@ export type Channel =
| NewsChannel
| StageChannel
| TextChannel
| AnyThreadChannel
| PublicThreadChannel
| PrivateThreadChannel
| VoiceChannel
| ForumChannel
| MediaChannel;
Expand Down Expand Up @@ -6674,7 +6679,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;

Expand Down
4 changes: 4 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ const client: Client = new Client({
maxSize: 200,
keepOverLimit: member => member.id === client.user?.id,
},
ThreadManager: {
maxSize: 200,
keepOverLimit: value => !value.archived,
},
}),
});

Expand Down
Loading