types: fix return type of toString() on channels (#7836)

* types(DMChannel): `toString()` returns a `UserMention`

* test: add more tests
This commit is contained in:
Almeida
2022-04-25 23:31:05 +01:00
committed by GitHub
parent f4ccc6772c
commit ece628986c
2 changed files with 21 additions and 1 deletions

View File

@@ -745,7 +745,7 @@ export abstract class Channel extends Base {
public isTextBased(): this is TextBasedChannel;
public isDMBased(): this is PartialGroupDMChannel | DMChannel | PartialDMChannel;
public isVoiceBased(): this is VoiceBasedChannel;
public toString(): ChannelMention;
public toString(): ChannelMention | UserMention;
}
export type If<T extends boolean, A, B = null> = T extends true ? A : T extends false ? B : A | B;
@@ -1075,6 +1075,7 @@ export class DMChannel extends TextBasedChannelMixin(Channel, ['bulkDelete']) {
public get recipient(): User | null;
public type: ChannelType.DM;
public fetch(force?: boolean): Promise<this>;
public toString(): UserMention;
}
export class Emoji extends Base {
@@ -1274,6 +1275,7 @@ export abstract class GuildChannel extends Channel {
public setParent(channel: CategoryChannelResolvable | null, options?: SetParentOptions): Promise<this>;
public setPosition(position: number, options?: SetChannelPositionOptions): Promise<this>;
public isTextBased(): this is GuildBasedChannel & TextBasedChannel;
public toString(): ChannelMention;
}
export class GuildEmoji extends BaseGuildEmoji {
@@ -1960,6 +1962,7 @@ export class PartialGroupDMChannel extends Channel {
public icon: string | null;
public recipients: PartialRecipient[];
public iconURL(options?: ImageURLOptions): string | null;
public toString(): ChannelMention;
}
export class PermissionOverwrites extends Base {
@@ -2464,6 +2467,7 @@ export class ThreadChannel extends TextBasedChannelMixin(Channel) {
public setLocked(locked?: boolean, reason?: string): Promise<ThreadChannel>;
public setName(name: string, reason?: string): Promise<ThreadChannel>;
public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise<ThreadChannel>;
public toString(): ChannelMention;
}
export class ThreadMember extends Base {

View File

@@ -120,6 +120,9 @@ import {
GuildBanManager,
GuildBan,
MessageManager,
ChannelMention,
UserMention,
PartialGroupDMChannel,
} from '.';
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
import { UnsafeButtonBuilder, UnsafeEmbedBuilder, UnsafeSelectMenuBuilder } from '@discordjs/builders';
@@ -1533,3 +1536,16 @@ EmbedBuilder.from(embedData);
declare const embedComp: Embed;
EmbedBuilder.from(embedComp);
declare const stageChannel: StageChannel;
declare const partialGroupDMChannel: PartialGroupDMChannel;
expectType<ChannelMention>(textChannel.toString());
expectType<ChannelMention>(voiceChannel.toString());
expectType<ChannelMention>(newsChannel.toString());
expectType<ChannelMention>(threadChannel.toString());
expectType<ChannelMention>(stageChannel.toString());
expectType<ChannelMention>(partialGroupDMChannel.toString());
expectType<UserMention>(dmChannel.toString());
expectType<UserMention>(user.toString());
expectType<UserMention>(guildMember.toString());