From a8567fd6d6605d0701c4a6c439e41476ede3f1af Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Wed, 30 Jun 2021 16:27:15 +0530 Subject: [PATCH 1/2] feat(Channel): add isThread typeguard for better TS support --- src/structures/Channel.js | 8 ++++++++ typings/index.d.ts | 1 + 2 files changed, 9 insertions(+) diff --git a/src/structures/Channel.js b/src/structures/Channel.js index 6c8e759c1b0c..06266d3d19c5 100644 --- a/src/structures/Channel.js +++ b/src/structures/Channel.js @@ -110,6 +110,14 @@ class Channel extends Base { return 'messages' in this; } + /** + * Indicates whether this channel is a thread channel. + * @returns {boolean} + */ + isThread() { + return ['news_thread', 'public_thread', 'private_thread'].includes(this.type); + } + static create(client, data, guild) { const Structures = require('../util/Structures'); let channel; diff --git a/typings/index.d.ts b/typings/index.d.ts index 1d756d828f1f..43d12f69d8f4 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -438,6 +438,7 @@ declare module 'discord.js' { public delete(reason?: string): Promise; public fetch(force?: boolean): Promise; public isText(): this is TextChannel | DMChannel | NewsChannel | ThreadChannel; + public isThread(): this is ThreadChannel; public toString(): string; } From 637b86e94fc414b88c218bd51740e6e19815ad58 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Wed, 30 Jun 2021 17:24:23 +0530 Subject: [PATCH 2/2] refactor(Channel): use ThreadChannelTypes constant in isThread --- src/structures/Channel.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/Channel.js b/src/structures/Channel.js index 06266d3d19c5..cdae8152a586 100644 --- a/src/structures/Channel.js +++ b/src/structures/Channel.js @@ -1,7 +1,7 @@ 'use strict'; const Base = require('./Base'); -const { ChannelTypes } = require('../util/Constants'); +const { ChannelTypes, ThreadChannelTypes } = require('../util/Constants'); const SnowflakeUtil = require('../util/SnowflakeUtil'); /** @@ -115,7 +115,7 @@ class Channel extends Base { * @returns {boolean} */ isThread() { - return ['news_thread', 'public_thread', 'private_thread'].includes(this.type); + return ThreadChannelTypes.includes(this.type); } static create(client, data, guild) {