From 70c733bb9a5bde0f79e6bea0bdc416458bda4c06 Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> Date: Sun, 5 Jun 2022 17:29:05 -0400 Subject: [PATCH] refactor(channel): remove redundant channel type guards (#8012) --- packages/discord.js/src/structures/Channel.js | 73 ------------------- packages/discord.js/typings/index.d.ts | 9 --- packages/discord.js/typings/index.test-d.ts | 4 +- 3 files changed, 2 insertions(+), 84 deletions(-) diff --git a/packages/discord.js/src/structures/Channel.js b/packages/discord.js/src/structures/Channel.js index a47ffb233..d4061088c 100644 --- a/packages/discord.js/src/structures/Channel.js +++ b/packages/discord.js/src/structures/Channel.js @@ -3,7 +3,6 @@ const { DiscordSnowflake } = require('@sapphire/snowflake'); const { ChannelType, Routes } = require('discord-api-types/v10'); const Base = require('./Base'); -const { ThreadChannelTypes } = require('../util/Constants'); let CategoryChannel; let DMChannel; let NewsChannel; @@ -110,78 +109,6 @@ class Channel extends Base { return this.client.channels.fetch(this.id, { force }); } - /** - * Indicates whether this channel is a {@link TextChannel}. - * @returns {boolean} - */ - isText() { - return this.type === ChannelType.GuildText; - } - - /** - * Indicates whether this channel is a {@link DMChannel}. - * @returns {boolean} - */ - isDM() { - return this.type === ChannelType.DM; - } - - /** - * Indicates whether this channel is a {@link VoiceChannel}. - * @returns {boolean} - */ - isVoice() { - return this.type === ChannelType.GuildVoice; - } - - /** - * Indicates whether this channel is a {@link PartialGroupDMChannel}. - * @returns {boolean} - */ - isGroupDM() { - return this.type === ChannelType.GroupDM; - } - - /** - * Indicates whether this channel is a {@link CategoryChannel}. - * @returns {boolean} - */ - isCategory() { - return this.type === ChannelType.GuildCategory; - } - - /** - * Indicates whether this channel is a {@link NewsChannel}. - * @returns {boolean} - */ - isNews() { - return this.type === ChannelType.GuildNews; - } - - /** - * Indicates whether this channel is a {@link ThreadChannel}. - * @returns {boolean} - */ - isThread() { - return ThreadChannelTypes.includes(this.type); - } - - /** - * Indicates whether this channel is a {@link StageChannel}. - * @returns {boolean} - */ - isStage() { - return this.type === ChannelType.GuildStageVoice; - } - - /** - * Indicates whether this channel is a {@link DirectoryChannel} - * @returns {boolean} - */ - isDirectory() { - return this.type === ChannelType.GuildDirectory; - } - /** * Indicates whether this channel is {@link TextBasedChannels text-based}. * @returns {boolean} diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 3d121dafd..55b25f9d6 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -748,15 +748,6 @@ export abstract class Channel extends Base { public get url(): string; public delete(): Promise; public fetch(force?: boolean): Promise; - public isText(): this is TextChannel; - public isDM(): this is DMChannel; - public isVoice(): this is VoiceChannel; - public isGroupDM(): this is PartialGroupDMChannel; - public isCategory(): this is CategoryChannel; - public isNews(): this is NewsChannel; - public isThread(): this is ThreadChannel; - public isStage(): this is StageChannel; - public isDirectory(): this is DirectoryChannel; public isTextBased(): this is TextBasedChannel; public isDMBased(): this is PartialGroupDMChannel | DMChannel | PartialDMChannel; public isVoiceBased(): this is VoiceBasedChannel; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 84fbb616a..6913113b7 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -529,7 +529,7 @@ client.on('guildCreate', async g => { const channel = g.channels.cache.random(); if (!channel) return; - if (channel.isText()) { + if (channel.type === ChannelType.GuildText) { const row: ActionRowData = { type: ComponentType.ActionRow, components: [ @@ -557,7 +557,7 @@ client.on('guildCreate', async g => { channel.send({ components: [row, row2] }); } - if (channel.isThread()) { + if (channel.type === ChannelType.GuildPublicThread) { const fetchedMember = await channel.members.fetch({ member: '12345678' }); expectType(fetchedMember); const fetchedMemberCol = await channel.members.fetch(true);