Skip to content

Commit

Permalink
fix(ThreadChannel): Add forum channel to parent (#8664)
Browse files Browse the repository at this point in the history
fix(ThreadChannel): add forum channel to parent

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
Jiralite and kodiakhq[bot] committed Sep 24, 2022
1 parent e993122 commit 0126d9b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/ThreadChannel.js
Expand Up @@ -246,7 +246,7 @@ class ThreadChannel extends BaseChannel {

/**
* The parent channel of this thread
* @type {?(NewsChannel|TextChannel)}
* @type {?(NewsChannel|TextChannel|ForumChannel)}
* @readonly
*/
get parent() {
Expand Down
26 changes: 14 additions & 12 deletions packages/discord.js/typings/index.d.ts
Expand Up @@ -2565,19 +2565,19 @@ export class TextChannel extends BaseGuildTextChannel {
public type: ChannelType.GuildText;
}

export type AnyThreadChannel = PublicThreadChannel | PrivateThreadChannel;
export type AnyThreadChannel<Forum extends boolean = boolean> = PublicThreadChannel<Forum> | PrivateThreadChannel;

export interface PublicThreadChannel extends ThreadChannel {
export interface PublicThreadChannel<Forum extends boolean = boolean> extends ThreadChannel<Forum> {
type: ChannelType.PublicThread | ChannelType.AnnouncementThread;
}

export interface PrivateThreadChannel extends ThreadChannel {
export interface PrivateThreadChannel extends ThreadChannel<false> {
get createdTimestamp(): number;
get createdAt(): Date;
type: ChannelType.PrivateThread;
}

export class ThreadChannel extends TextBasedChannelMixin(BaseChannel, true, [
export class ThreadChannel<Forum extends boolean = boolean> extends TextBasedChannelMixin(BaseChannel, true, [
'fetchWebhooks',
'createWebhook',
'setNSFW',
Expand Down Expand Up @@ -2609,7 +2609,7 @@ export class ThreadChannel extends TextBasedChannelMixin(BaseChannel, true, [
public members: ThreadMemberManager;
public name: string;
public ownerId: Snowflake | null;
public get parent(): TextChannel | NewsChannel | null;
public get parent(): If<Forum, ForumChannel, TextChannel | NewsChannel> | null;
public parentId: Snowflake | null;
public rateLimitPerUser: number | null;
public type: ThreadChannelType;
Expand All @@ -2633,7 +2633,7 @@ export class ThreadChannel extends TextBasedChannelMixin(BaseChannel, true, [
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 setAppliedTags(appliedTags: Snowflake[], reason?: string): Promise<ThreadChannel>;
public setAppliedTags(appliedTags: Snowflake[], reason?: string): Promise<ThreadChannel<true>>;
public toString(): ChannelMention;
}

Expand Down Expand Up @@ -3698,22 +3698,24 @@ export class StageInstanceManager extends CachedManager<Snowflake, StageInstance
public delete(channel: StageChannelResolvable): Promise<void>;
}

export class ThreadManager extends CachedManager<Snowflake, ThreadChannel, ThreadChannelResolvable> {
export class ThreadManager<Forum extends boolean = boolean> extends CachedManager<
Snowflake,
ThreadChannel<Forum>,
ThreadChannelResolvable
> {
protected constructor(channel: TextChannel | NewsChannel | ForumChannel, iterable?: Iterable<RawThreadChannelData>);
public channel: TextChannel | NewsChannel | ForumChannel;
public channel: If<Forum, ForumChannel, TextChannel | NewsChannel>;
public fetch(options: ThreadChannelResolvable, cacheOptions?: BaseFetchOptions): Promise<AnyThreadChannel | null>;
public fetch(options?: FetchThreadsOptions, cacheOptions?: { cache?: boolean }): Promise<FetchedThreads>;
public fetchArchived(options?: FetchArchivedThreadOptions, cache?: boolean): Promise<FetchedThreads>;
public fetchActive(cache?: boolean): Promise<FetchedThreads>;
}

export class GuildTextThreadManager<AllowedThreadType> extends ThreadManager {
public channel: TextChannel | NewsChannel;
export class GuildTextThreadManager<AllowedThreadType> extends ThreadManager<false> {
public create(options: GuildTextThreadCreateOptions<AllowedThreadType>): Promise<ThreadChannel>;
}

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

Expand Down
17 changes: 17 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Expand Up @@ -139,6 +139,8 @@ import {
ModalSubmitInteraction,
ForumChannel,
ChannelFlagsBitField,
GuildForumThreadManager,
GuildTextThreadManager,
} from '.';
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
Expand Down Expand Up @@ -1224,13 +1226,20 @@ expectType<Promise<number[]>>(shardClientUtil.broadcastEval(async () => 1));

declare const dmChannel: DMChannel;
declare const threadChannel: ThreadChannel;
declare const threadChannelFromForum: ThreadChannel<true>;
declare const threadChannelNotFromForum: ThreadChannel<false>;
declare const newsChannel: NewsChannel;
declare const textChannel: TextChannel;
declare const voiceChannel: VoiceChannel;
declare const guild: Guild;
declare const user: User;
declare const guildMember: GuildMember;

// Test thread channels' parent inference
expectType<TextChannel | NewsChannel | ForumChannel | null>(threadChannel.parent);
expectType<ForumChannel | null>(threadChannelFromForum.parent);
expectType<TextChannel | NewsChannel | null>(threadChannelNotFromForum.parent);

// Test whether the structures implement send
expectType<TextBasedChannelFields<false>['send']>(dmChannel.send);
expectType<TextBasedChannelFields<true>['send']>(threadChannel.send);
Expand Down Expand Up @@ -1406,6 +1415,14 @@ declare const guildChannelManager: GuildChannelManager;
expectType<TextBasedChannel>(message.channel.messages.channel);
}

declare const guildForumThreadManager: GuildForumThreadManager;
expectType<ForumChannel>(guildForumThreadManager.channel);

declare const guildTextThreadManager: GuildTextThreadManager<
ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread
>;
expectType<TextChannel | NewsChannel>(guildTextThreadManager.channel);

declare const messageManager: MessageManager;
{
expectType<Promise<Message>>(messageManager.fetch('1234567890'));
Expand Down

0 comments on commit 0126d9b

Please sign in to comment.