refactor: added TextBasedChannels type (#6286)

This commit is contained in:
Antonio Román
2021-08-04 00:12:51 +02:00
committed by GitHub
parent a72b5a355e
commit 61db5f7618
12 changed files with 42 additions and 45 deletions

48
typings/index.d.ts vendored
View File

@@ -330,7 +330,7 @@ export class Channel extends Base {
public type: keyof typeof ChannelTypes;
public delete(): Promise<Channel>;
public fetch(force?: boolean): Promise<Channel>;
public isText(): this is TextChannel | DMChannel | NewsChannel | ThreadChannel;
public isText(): this is TextBasedChannels;
public isThread(): this is ThreadChannel;
public toString(): ChannelMention;
}
@@ -472,7 +472,7 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
export class CommandInteraction extends Interaction {
public constructor(client: Client, data: RawCommandInteractionData);
public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
public readonly channel: TextChannel | DMChannel | NewsChannel | PartialDMChannel | ThreadChannel | null;
public readonly channel: TextBasedChannels | null;
public channelId: Snowflake;
public commandId: Snowflake;
public commandName: string;
@@ -939,7 +939,7 @@ export class Intents extends BitField<IntentsString> {
export class Interaction extends Base {
public constructor(client: Client, data: RawInteractionData);
public applicationId: Snowflake;
public readonly channel: Channel | PartialDMChannel | null;
public readonly channel: TextBasedChannels | null;
public channelId: Snowflake | null;
public readonly createdAt: Date;
public readonly createdTimestamp: number;
@@ -964,7 +964,7 @@ export class InteractionCollector<T extends Interaction> extends Collector<Snowf
private _handleChannelDeletion(channel: GuildChannel): void;
private _handleGuildDeletion(guild: Guild): void;
public channel: TextChannel | NewsChannel | DMChannel | null;
public channel: TextBasedChannels | null;
public componentType: MessageComponentType | null;
public readonly endReason: string | null;
public guild: Guild | null;
@@ -1048,11 +1048,7 @@ export class LimitedCollection<K, V> extends Collection<K, V> {
}
export class Message extends Base {
public constructor(
client: Client,
data: RawMessageData,
channel: TextChannel | DMChannel | NewsChannel | ThreadChannel,
);
public constructor(client: Client, data: RawMessageData, channel: TextBasedChannels);
private _patch(data: RawPartialMessageData, partial: true): Message;
private _patch(data: RawMessageData, partial?: boolean): Message;
private _update(data: RawPartialMessageData, partial: true): Message;
@@ -1062,7 +1058,7 @@ export class Message extends Base {
public applicationId: Snowflake | null;
public attachments: Collection<Snowflake, MessageAttachment>;
public author: User;
public channel: TextChannel | DMChannel | NewsChannel | ThreadChannel;
public channel: TextBasedChannels;
public readonly cleanContent: string;
public components: MessageActionRow[];
public content: string;
@@ -1175,11 +1171,11 @@ export class MessageButton extends BaseMessageComponent {
}
export class MessageCollector extends Collector<Snowflake, Message> {
public constructor(channel: TextChannel | DMChannel | ThreadChannel, options?: MessageCollectorOptions);
public constructor(channel: TextBasedChannels, options?: MessageCollectorOptions);
private _handleChannelDeletion(channel: GuildChannel): void;
private _handleGuildDeletion(guild: Guild): void;
public channel: TextChannel | DMChannel | ThreadChannel;
public channel: TextBasedChannels;
public readonly endReason: string | null;
public options: MessageCollectorOptions;
public received: number;
@@ -1190,7 +1186,7 @@ export class MessageCollector extends Collector<Snowflake, Message> {
export class MessageComponentInteraction extends Interaction {
public constructor(client: Client, data: RawMessageComponentInteractionData);
public readonly channel: TextChannel | DMChannel | NewsChannel | PartialDMChannel | ThreadChannel | null;
public readonly channel: TextBasedChannels | null;
public readonly component: MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent> | null;
public componentType: MessageComponentType;
public customId: string;
@@ -1813,12 +1809,8 @@ export class ThreadMemberFlags extends BitField<ThreadMemberFlagsString> {
}
export class Typing extends Base {
public constructor(
channel: TextChannel | PartialDMChannel | NewsChannel | ThreadChannel,
user: PartialUser,
data?: RawTypingData,
);
public channel: TextChannel | PartialDMChannel | NewsChannel | ThreadChannel;
public constructor(channel: TextBasedChannels, user: PartialUser, data?: RawTypingData);
public channel: TextBasedChannels;
public user: PartialUser;
public startedTimestamp: number;
public readonly startedAt: Date;
@@ -2499,8 +2491,8 @@ export class GuildMemberRoleManager extends DataManager<Snowflake, Role, RoleRes
}
export class MessageManager extends CachedManager<Snowflake, Message, MessageResolvable> {
public constructor(channel: TextChannel | DMChannel | ThreadChannel, iterable?: Iterable<RawMessageData>);
public channel: TextBasedChannelFields;
public constructor(channel: TextBasedChannels, iterable?: Iterable<RawMessageData>);
public channel: TextBasedChannels;
public cache: Collection<Snowflake, Message>;
public crosspost(message: MessageResolvable): Promise<Message>;
public delete(message: MessageResolvable): Promise<void>;
@@ -3039,7 +3031,7 @@ export interface ClientEvents {
applicationCommandUpdate: [oldCommand: ApplicationCommand | null, newCommand: ApplicationCommand];
channelCreate: [channel: GuildChannel];
channelDelete: [channel: DMChannel | GuildChannel];
channelPinsUpdate: [channel: TextChannel | NewsChannel | DMChannel | PartialDMChannel, date: Date];
channelPinsUpdate: [channel: TextBasedChannels, date: Date];
channelUpdate: [oldChannel: DMChannel | GuildChannel, newChannel: DMChannel | GuildChannel];
debug: [message: string];
warn: [message: string];
@@ -3788,7 +3780,7 @@ export interface IntegrationAccount {
}
export interface InteractionCollectorOptions<T extends Interaction> extends CollectorOptions<[T]> {
channel?: TextChannel | DMChannel | NewsChannel | ThreadChannel;
channel?: TextBasedChannels;
componentType?: MessageComponentType | MessageComponentTypes;
guild?: Guild;
interactionType?: InteractionType | InteractionTypes;
@@ -4421,13 +4413,9 @@ export interface LimitedCollectionOptions<K, V> {
sweepInterval?: number;
}
export type TextBasedChannelTypes =
| 'DM'
| 'GUILD_TEXT'
| 'GUILD_NEWS'
| 'GUILD_NEWS_THREAD'
| 'GUILD_PUBLIC_THREAD'
| 'GUILD_PRIVATE_THREAD';
export type TextBasedChannels = PartialDMChannel | DMChannel | TextChannel | NewsChannel | ThreadChannel;
export type TextBasedChannelTypes = TextBasedChannels['type'];
export type TextChannelResolvable = Snowflake | TextChannel;

View File

@@ -49,6 +49,7 @@ import {
StageChannel,
StoreChannel,
TextBasedChannelFields,
TextBasedChannels,
TextChannel,
ThreadChannel,
Typing,
@@ -662,7 +663,7 @@ declare const typing: Typing;
assertType<PartialUser>(typing.user);
if (typing.user.partial) assertType<null>(typing.user.username);
assertType<TextChannel | PartialDMChannel | NewsChannel | ThreadChannel>(typing.channel);
assertType<TextBasedChannels>(typing.channel);
if (typing.channel.partial) assertType<undefined>(typing.channel.lastMessageId);
assertType<GuildMember | null>(typing.member);