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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
49 changes: 27 additions & 22 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,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 @@ -3199,7 +3199,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 @@ -3248,28 +3250,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 @@ -4510,15 +4509,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 @@ -4529,11 +4531,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 @@ -6724,7 +6728,8 @@ export type Channel =
| NewsChannel
| StageChannel
| TextChannel
| AnyThreadChannel
| PublicThreadChannel
| PrivateThreadChannel
| VoiceChannel
| ForumChannel
| MediaChannel;
Expand Down Expand Up @@ -6754,7 +6759,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 @@ -227,6 +227,10 @@ const client: Client = new Client({
maxSize: 200,
keepOverLimit: member => member.id === client.user?.id,
},
ThreadManager: {
maxSize: 200,
keepOverLimit: value => !value.archived,
},
}),
});

Expand Down