From ece628986c7eb1a66f46076d8f8518c9ff00aaf3 Mon Sep 17 00:00:00 2001 From: Almeida Date: Mon, 25 Apr 2022 23:31:05 +0100 Subject: [PATCH] types: fix return type of `toString()` on channels (#7836) * types(DMChannel): `toString()` returns a `UserMention` * test: add more tests --- packages/discord.js/typings/index.d.ts | 6 +++++- packages/discord.js/typings/index.test-d.ts | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index dee957a23..b5d95f152 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -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 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; + 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; public setPosition(position: number, options?: SetChannelPositionOptions): Promise; 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; public setName(name: string, reason?: string): Promise; public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise; + public toString(): ChannelMention; } export class ThreadMember extends Base { diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 2d00e4007..b7b31c99f 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -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(textChannel.toString()); +expectType(voiceChannel.toString()); +expectType(newsChannel.toString()); +expectType(threadChannel.toString()); +expectType(stageChannel.toString()); +expectType(partialGroupDMChannel.toString()); +expectType(dmChannel.toString()); +expectType(user.toString()); +expectType(guildMember.toString());