Skip to content

Commit

Permalink
types: Use ThreadChannel and AnyThreadChannel consistently (#10181)
Browse files Browse the repository at this point in the history
* types: Use `ThreadChannel` and `AnyThreadChannel` consistently

Signed-off-by: RedGuy12 <[email protected]>

* types: use union in typeguard

Signed-off-by: cobalt <[email protected]>

* types: update `AnyThreadChannel`

Signed-off-by: cobalt <[email protected]>

* types: fix `CommandOptionResolver` tests

Signed-off-by: cobalt <[email protected]>

* types: revert caches changes

Signed-off-by: cobalt <[email protected]>

---------

Signed-off-by: RedGuy12 <[email protected]>
Signed-off-by: cobalt <[email protected]>
Co-authored-by: RedGuy12 <[email protected]>
Co-authored-by: Jiralite <[email protected]>
Co-authored-by: Almeida <[email protected]>
  • Loading branch information
4 people committed Aug 20, 2024
1 parent 9907ff9 commit 1f7d1f8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
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 @@ -2186,7 +2186,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 @@ -3249,7 +3249,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 @@ -3298,28 +3300,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>>;
public toString(): ChannelMention;
}

Expand Down Expand Up @@ -4568,15 +4567,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 @@ -4587,11 +4589,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 @@ -6792,7 +6796,8 @@ export type Channel =
| NewsChannel
| StageChannel
| TextChannel
| AnyThreadChannel
| PublicThreadChannel
| PrivateThreadChannel
| VoiceChannel
| ForumChannel
| MediaChannel;
Expand Down Expand Up @@ -6822,7 +6827,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 @@ -230,6 +230,10 @@ const client: Client = new Client({
maxSize: 200,
keepOverLimit: member => member.id === client.user?.id,
},
ThreadManager: {
maxSize: 200,
keepOverLimit: value => !value.archived,
},
}),
});

Expand Down

0 comments on commit 1f7d1f8

Please sign in to comment.