From cba0102ae5cab66c2c75dd013c89d8e2e2e50e4e Mon Sep 17 00:00:00 2001 From: Qjuh <76154676+Qjuh@users.noreply.github.com> Date: Sun, 21 Jan 2024 13:14:48 +0100 Subject: [PATCH 1/3] types(TextBasedChannelMixin): refactor to user interface merging instead --- packages/discord.js/typings/index.d.ts | 82 +++++++++++--------------- 1 file changed, 36 insertions(+), 46 deletions(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index cef54e1b8b4f..413cbc52d899 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -647,7 +647,8 @@ export class BaseGuildEmoji extends Emoji { public requiresColons: boolean | null; } -export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel, true) { +export interface BaseGuildTextChannel extends TextBasedChannelFields, GuildChannel {} +export class BaseGuildTextChannel extends GuildChannel { protected constructor(guild: Guild, data?: RawGuildChannelData, client?: Client, immediatePatch?: boolean); public defaultAutoArchiveDuration?: ThreadAutoArchiveDuration; public defaultThreadRateLimitPerUser: number | null; @@ -666,10 +667,10 @@ export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel, tr public setType(type: ChannelType.GuildAnnouncement, reason?: string): Promise; } -export class BaseGuildVoiceChannel extends TextBasedChannelMixin(GuildChannel, true, [ - 'lastPinTimestamp', - 'lastPinAt', -]) { +export interface BaseGuildVoiceChannel + extends Omit, 'lastPinTimestamp' | 'lastPinAt'>, + GuildChannel {} +export class BaseGuildVoiceChannel extends GuildChannel { public constructor(guild: Guild, data?: RawGuildChannelData); public bitrate: number; public get full(): boolean; @@ -1283,13 +1284,13 @@ export interface ResolvedFile { contentType?: string; } -export class DMChannel extends TextBasedChannelMixin(BaseChannel, false, [ - 'bulkDelete', - 'fetchWebhooks', - 'createWebhook', - 'setRateLimitPerUser', - 'setNSFW', -]) { +export interface DMChannel + extends Omit< + TextBasedChannelFields, + 'bulkDelete' | 'fetchWebhooks' | 'createWebhook' | 'setRateLimitPerUser' | 'setNSFW' + >, + BaseChannel {} +export class DMChannel extends BaseChannel { private constructor(client: Client, data?: RawDMChannelData); public flags: Readonly; public recipientId: Snowflake; @@ -1568,7 +1569,8 @@ export class GuildMemberFlagsBitField extends BitField { public static resolve(bit?: BitFieldResolvable): number; } -export class GuildMember extends PartialTextBasedChannel(Base) { +export interface GuildMember extends PartialTextBasedChannelFields, Base {} +export class GuildMember extends Base { private constructor(client: Client, data: RawGuildMemberData, guild: Guild); private _roles: Snowflake[]; public avatar: string | null; @@ -2463,17 +2465,21 @@ export interface DefaultReactionEmoji { name: string | null; } -export abstract class ThreadOnlyChannel extends TextBasedChannelMixin(GuildChannel, true, [ - 'send', - 'lastMessage', - 'lastPinAt', - 'bulkDelete', - 'sendTyping', - 'createMessageCollector', - 'awaitMessages', - 'createMessageComponentCollector', - 'awaitMessageComponent', -]) { +export interface ThreadOnlyChannel + extends Omit< + TextBasedChannelFields, + | 'send' + | 'lastMessage' + | 'lastPinAt' + | 'bulkDelete' + | 'sendTyping' + | 'createMessageCollector' + | 'awaitMessages' + | 'createMessageComponentCollector' + | 'awaitMessageComponent' + >, + GuildChannel {} +export abstract class ThreadOnlyChannel extends GuildChannel { public type: ChannelType.GuildForum | ChannelType.GuildMedia; public threads: GuildForumThreadManager; public availableTags: GuildForumTag[]; @@ -3133,11 +3139,10 @@ export interface PrivateThreadChannel extends ThreadChannel { type: ChannelType.PrivateThread; } -export class ThreadChannel extends TextBasedChannelMixin(BaseChannel, true, [ - 'fetchWebhooks', - 'createWebhook', - 'setNSFW', -]) { +export interface ThreadChannel + extends Omit, 'fetchWebhooks' | 'createWebhook' | 'setNSFW'>, + BaseChannel {} +export class ThreadChannel extends BaseChannel { private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client); public archived: boolean | null; public get archivedAt(): Date | null; @@ -3232,7 +3237,8 @@ export class Typing extends Base { }; } -export class User extends PartialTextBasedChannel(Base) { +export interface User extends PartialTextBasedChannelFields, Base {} +export class User extends Base { protected constructor(client: Client, data: RawUserData); private _equals(user: APIUser): boolean; @@ -4468,22 +4474,6 @@ export class VoiceStateManager extends CachedManager = abstract new (...args: any[]) => Entity; -/** @internal */ -export function PartialTextBasedChannel( - Base?: Constructable, -): Constructable>; - -/** @internal */ -export function TextBasedChannelMixin< - Entity, - InGuild extends boolean = boolean, - IgnoredFields extends keyof TextBasedChannelFields = never, ->( - Base?: Constructable, - inGuild?: InGuild, - ignore?: IgnoredFields[], -): Constructable, IgnoredFields>>; - export interface PartialTextBasedChannelFields { send(options: string | MessagePayload | MessageCreateOptions): Promise>; } From b91f81515a58eb994ad9062d2bc172dafaeded39 Mon Sep 17 00:00:00 2001 From: Qjuh <76154676+Qjuh@users.noreply.github.com> Date: Sun, 21 Jan 2024 14:43:16 +0100 Subject: [PATCH 2/3] types(WebhookMixin): refactor to interface merging --- packages/discord.js/typings/index.d.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 413cbc52d899..9917f6ef52f7 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1921,7 +1921,8 @@ export class InteractionCollector exte public once(event: string, listener: (...args: any[]) => void): this; } -export class InteractionWebhook extends PartialWebhookMixin() { +export interface InteractionWebhook extends PartialWebhookFields {} +export class InteractionWebhook { public constructor(client: Client, id: Snowflake, token: string); public readonly client: Client; public token: string; @@ -3491,7 +3492,8 @@ export class VoiceState extends Base { public edit(options: VoiceStateEditOptions): Promise; } -export class Webhook extends WebhookMixin() { +export interface Webhook extends WebhookFields {} +export class Webhook { private constructor(client: Client, data?: RawWebhookData); public avatar: string | null; public avatarURL(options?: ImageURLOptions): string | null; @@ -3537,7 +3539,8 @@ export class Webhook extends WebhookMixin() { public send(options: string | MessagePayload | WebhookMessageCreateOptions): Promise; } -export class WebhookClient extends WebhookMixin(BaseClient) { +export interface WebhookClient extends WebhookFields, BaseClient {} +export class WebhookClient extends BaseClient { public constructor(data: WebhookClientData, options?: WebhookClientOptions); public readonly client: this; public options: WebhookClientOptions; @@ -4504,11 +4507,6 @@ export interface TextBasedChannelFields setNSFW(nsfw?: boolean, reason?: string): Promise; } -/** @internal */ -export function PartialWebhookMixin(Base?: Constructable): Constructable; -/** @internal */ -export function WebhookMixin(Base?: Constructable): Constructable; - /** @internal */ export interface PartialWebhookFields { id: Snowflake; From 34f4ffb35597ec9ce05245215731a5c147fdd406 Mon Sep 17 00:00:00 2001 From: Qjuh <76154676+Qjuh@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:18:20 +0100 Subject: [PATCH 3/3] fix: ignore empty-interface tslint errors --- packages/discord.js/typings/index.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 9917f6ef52f7..4014eca5e4aa 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -647,6 +647,7 @@ export class BaseGuildEmoji extends Emoji { public requiresColons: boolean | null; } +// tslint:disable-next-line no-empty-interface export interface BaseGuildTextChannel extends TextBasedChannelFields, GuildChannel {} export class BaseGuildTextChannel extends GuildChannel { protected constructor(guild: Guild, data?: RawGuildChannelData, client?: Client, immediatePatch?: boolean); @@ -667,6 +668,7 @@ export class BaseGuildTextChannel extends GuildChannel { public setType(type: ChannelType.GuildAnnouncement, reason?: string): Promise; } +// tslint:disable-next-line no-empty-interface export interface BaseGuildVoiceChannel extends Omit, 'lastPinTimestamp' | 'lastPinAt'>, GuildChannel {} @@ -1284,6 +1286,7 @@ export interface ResolvedFile { contentType?: string; } +// tslint:disable-next-line no-empty-interface export interface DMChannel extends Omit< TextBasedChannelFields, @@ -1921,6 +1924,7 @@ export class InteractionCollector exte public once(event: string, listener: (...args: any[]) => void): this; } +// tslint:disable-next-line no-empty-interface export interface InteractionWebhook extends PartialWebhookFields {} export class InteractionWebhook { public constructor(client: Client, id: Snowflake, token: string); @@ -3140,6 +3144,7 @@ export interface PrivateThreadChannel extends ThreadChannel { type: ChannelType.PrivateThread; } +// tslint:disable-next-line no-empty-interface export interface ThreadChannel extends Omit, 'fetchWebhooks' | 'createWebhook' | 'setNSFW'>, BaseChannel {} @@ -3238,6 +3243,7 @@ export class Typing extends Base { }; } +// tslint:disable-next-line no-empty-interface export interface User extends PartialTextBasedChannelFields, Base {} export class User extends Base { protected constructor(client: Client, data: RawUserData); @@ -3492,6 +3498,7 @@ export class VoiceState extends Base { public edit(options: VoiceStateEditOptions): Promise; } +// tslint:disable-next-line no-empty-interface export interface Webhook extends WebhookFields {} export class Webhook { private constructor(client: Client, data?: RawWebhookData); @@ -3539,6 +3546,7 @@ export class Webhook { public send(options: string | MessagePayload | WebhookMessageCreateOptions): Promise; } +// tslint:disable-next-line no-empty-interface export interface WebhookClient extends WebhookFields, BaseClient {} export class WebhookClient extends BaseClient { public constructor(data: WebhookClientData, options?: WebhookClientOptions);