feat(Channel): add isThread typeguard for better TS support (#5978)

This commit is contained in:
Shubham Parihar
2021-06-30 20:49:59 +05:30
committed by GitHub
parent 788d58e5a3
commit b7ed6752ac
2 changed files with 10 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
'use strict'; 'use strict';
const Base = require('./Base'); const Base = require('./Base');
const { ChannelTypes } = require('../util/Constants'); const { ChannelTypes, ThreadChannelTypes } = require('../util/Constants');
const SnowflakeUtil = require('../util/SnowflakeUtil'); const SnowflakeUtil = require('../util/SnowflakeUtil');
/** /**
@@ -110,6 +110,14 @@ class Channel extends Base {
return 'messages' in this; return 'messages' in this;
} }
/**
* Indicates whether this channel is a thread channel.
* @returns {boolean}
*/
isThread() {
return ThreadChannelTypes.includes(this.type);
}
static create(client, data, guild) { static create(client, data, guild) {
const Structures = require('../util/Structures'); const Structures = require('../util/Structures');
let channel; let channel;

1
typings/index.d.ts vendored
View File

@@ -438,6 +438,7 @@ declare module 'discord.js' {
public delete(reason?: string): Promise<Channel>; public delete(reason?: string): Promise<Channel>;
public fetch(force?: boolean): Promise<Channel>; public fetch(force?: boolean): Promise<Channel>;
public isText(): this is TextChannel | DMChannel | NewsChannel | ThreadChannel; public isText(): this is TextChannel | DMChannel | NewsChannel | ThreadChannel;
public isThread(): this is ThreadChannel;
public toString(): string; public toString(): string;
} }