Skip to content

Commit 1f7d1f8

Browse files
cobaltt7Jiralitealmeidx
authored
types: Use ThreadChannel and AnyThreadChannel consistently (#10181)
* 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]>
1 parent 9907ff9 commit 1f7d1f8

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

packages/discord.js/typings/index.d.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,7 +2186,7 @@ export class Message<InGuild extends boolean = boolean> extends Base {
21862186
public removeAttachments(): Promise<Message<InGuild>>;
21872187
public reply(options: string | MessagePayload | MessageReplyOptions): Promise<Message<InGuild>>;
21882188
public resolveComponent(customId: string): MessageActionRowComponent | null;
2189-
public startThread(options: StartThreadOptions): Promise<AnyThreadChannel>;
2189+
public startThread(options: StartThreadOptions): Promise<PublicThreadChannel<false>>;
21902190
public suppressEmbeds(suppress?: boolean): Promise<Message<InGuild>>;
21912191
public toJSON(): unknown;
21922192
public toString(): string;
@@ -3249,7 +3249,9 @@ export class TextChannel extends BaseGuildTextChannel {
32493249
public type: ChannelType.GuildText;
32503250
}
32513251

3252-
export type AnyThreadChannel<Forum extends boolean = boolean> = PublicThreadChannel<Forum> | PrivateThreadChannel;
3252+
export type ForumThreadChannel = PublicThreadChannel<true>;
3253+
export type TextThreadChannel = PublicThreadChannel<false> | PrivateThreadChannel;
3254+
export type AnyThreadChannel = TextThreadChannel | ForumThreadChannel;
32533255

32543256
export interface PublicThreadChannel<Forum extends boolean = boolean> extends ThreadChannel<Forum> {
32553257
type: ChannelType.PublicThread | ChannelType.AnnouncementThread;
@@ -3298,28 +3300,25 @@ export class ThreadChannel<ThreadOnly extends boolean = boolean> extends BaseCha
32983300
public type: ThreadChannelType;
32993301
public get unarchivable(): boolean;
33003302
public delete(reason?: string): Promise<this>;
3301-
public edit(options: ThreadEditOptions): Promise<AnyThreadChannel>;
3302-
public join(): Promise<AnyThreadChannel>;
3303-
public leave(): Promise<AnyThreadChannel>;
3303+
public edit(options: ThreadEditOptions): Promise<this>;
3304+
public join(): Promise<this>;
3305+
public leave(): Promise<this>;
33043306
public permissionsFor(memberOrRole: GuildMember | Role, checkAdmin?: boolean): Readonly<PermissionsBitField>;
33053307
public permissionsFor(
33063308
memberOrRole: GuildMemberResolvable | RoleResolvable,
33073309
checkAdmin?: boolean,
33083310
): Readonly<PermissionsBitField> | null;
33093311
public fetchOwner(options?: BaseFetchOptions): Promise<ThreadMember | null>;
33103312
public fetchStarterMessage(options?: BaseFetchOptions): Promise<Message<true> | null>;
3311-
public setArchived(archived?: boolean, reason?: string): Promise<AnyThreadChannel>;
3312-
public setAutoArchiveDuration(
3313-
autoArchiveDuration: ThreadAutoArchiveDuration,
3314-
reason?: string,
3315-
): Promise<AnyThreadChannel>;
3316-
public setInvitable(invitable?: boolean, reason?: string): Promise<AnyThreadChannel>;
3317-
public setLocked(locked?: boolean, reason?: string): Promise<AnyThreadChannel>;
3318-
public setName(name: string, reason?: string): Promise<AnyThreadChannel>;
3313+
public setArchived(archived?: boolean, reason?: string): Promise<this>;
3314+
public setAutoArchiveDuration(autoArchiveDuration: ThreadAutoArchiveDuration, reason?: string): Promise<this>;
3315+
public setInvitable(invitable?: boolean, reason?: string): Promise<this>;
3316+
public setLocked(locked?: boolean, reason?: string): Promise<this>;
3317+
public setName(name: string, reason?: string): Promise<this>;
33193318
// The following 3 methods can only be run on forum threads.
3320-
public setAppliedTags(appliedTags: readonly Snowflake[], reason?: string): Promise<ThreadChannel<true>>;
3321-
public pin(reason?: string): Promise<ThreadChannel<true>>;
3322-
public unpin(reason?: string): Promise<ThreadChannel<true>>;
3319+
public setAppliedTags(appliedTags: readonly Snowflake[], reason?: string): Promise<If<ThreadOnly, this, never>>;
3320+
public pin(reason?: string): Promise<If<ThreadOnly, this, never>>;
3321+
public unpin(reason?: string): Promise<If<ThreadOnly, this, never>>;
33233322
public toString(): ChannelMention;
33243323
}
33253324

@@ -4568,15 +4567,18 @@ export class StageInstanceManager extends CachedManager<Snowflake, StageInstance
45684567

45694568
export class ThreadManager<ThreadOnly extends boolean = boolean> extends CachedManager<
45704569
Snowflake,
4571-
ThreadChannel<ThreadOnly>,
4570+
If<ThreadOnly, ForumThreadChannel, TextThreadChannel>,
45724571
ThreadChannelResolvable
45734572
> {
45744573
protected constructor(
45754574
channel: TextChannel | NewsChannel | ForumChannel | MediaChannel,
45764575
iterable?: Iterable<RawThreadChannelData>,
45774576
);
45784577
public channel: If<ThreadOnly, ForumChannel | MediaChannel, TextChannel | NewsChannel>;
4579-
public fetch(options: ThreadChannelResolvable, cacheOptions?: BaseFetchOptions): Promise<AnyThreadChannel | null>;
4578+
public fetch(
4579+
options: ThreadChannelResolvable,
4580+
cacheOptions?: BaseFetchOptions,
4581+
): Promise<If<ThreadOnly, ForumThreadChannel, TextThreadChannel> | null>;
45804582
public fetch(
45814583
options: FetchThreadsOptions & { archived: FetchArchivedThreadOptions },
45824584
cacheOptions?: { cache?: boolean },
@@ -4587,11 +4589,13 @@ export class ThreadManager<ThreadOnly extends boolean = boolean> extends CachedM
45874589
}
45884590

45894591
export class GuildTextThreadManager<AllowedThreadType> extends ThreadManager<false> {
4590-
public create(options: GuildTextThreadCreateOptions<AllowedThreadType>): Promise<ThreadChannel>;
4592+
public create(
4593+
options: GuildTextThreadCreateOptions<AllowedThreadType>,
4594+
): Promise<AllowedThreadType extends ChannelType.PrivateThread ? PrivateThreadChannel : PublicThreadChannel<false>>;
45914595
}
45924596

45934597
export class GuildForumThreadManager extends ThreadManager<true> {
4594-
public create(options: GuildForumThreadCreateOptions): Promise<ThreadChannel>;
4598+
public create(options: GuildForumThreadCreateOptions): Promise<ForumThreadChannel>;
45954599
}
45964600

45974601
export class ThreadMemberManager extends CachedManager<Snowflake, ThreadMember, ThreadMemberResolvable> {
@@ -6792,7 +6796,8 @@ export type Channel =
67926796
| NewsChannel
67936797
| StageChannel
67946798
| TextChannel
6795-
| AnyThreadChannel
6799+
| PublicThreadChannel
6800+
| PrivateThreadChannel
67966801
| VoiceChannel
67976802
| ForumChannel
67986803
| MediaChannel;
@@ -6822,7 +6827,7 @@ export type TextChannelResolvable = Snowflake | TextChannel;
68226827

68236828
export type TextBasedChannelResolvable = Snowflake | TextBasedChannel;
68246829

6825-
export type ThreadChannelResolvable = AnyThreadChannel | Snowflake;
6830+
export type ThreadChannelResolvable = Snowflake | ThreadChannel;
68266831

68276832
export type ThreadChannelType = ChannelType.AnnouncementThread | ChannelType.PublicThread | ChannelType.PrivateThread;
68286833

packages/discord.js/typings/index.test-d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ const client: Client = new Client({
230230
maxSize: 200,
231231
keepOverLimit: member => member.id === client.user?.id,
232232
},
233+
ThreadManager: {
234+
maxSize: 200,
235+
keepOverLimit: value => !value.archived,
236+
},
233237
}),
234238
});
235239

0 commit comments

Comments
 (0)