Skip to content

Commit 54106db

Browse files
Qjuhkodiakhq[bot]
andauthoredFeb 11, 2024
types: replace Mixins with interface merging (#10094)
* types(TextBasedChannelMixin): refactor to user interface merging instead * types(WebhookMixin): refactor to interface merging * fix: ignore empty-interface tslint errors --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent ce6b2b7 commit 54106db

File tree

1 file changed

+50
-54
lines changed

1 file changed

+50
-54
lines changed
 

‎packages/discord.js/typings/index.d.ts

+50-54
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,9 @@ export class BaseGuildEmoji extends Emoji {
647647
public requiresColons: boolean | null;
648648
}
649649

650-
export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel, true) {
650+
// tslint:disable-next-line no-empty-interface
651+
export interface BaseGuildTextChannel extends TextBasedChannelFields<true>, GuildChannel {}
652+
export class BaseGuildTextChannel extends GuildChannel {
651653
protected constructor(guild: Guild, data?: RawGuildChannelData, client?: Client<true>, immediatePatch?: boolean);
652654
public defaultAutoArchiveDuration?: ThreadAutoArchiveDuration;
653655
public defaultThreadRateLimitPerUser: number | null;
@@ -666,10 +668,11 @@ export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel, tr
666668
public setType(type: ChannelType.GuildAnnouncement, reason?: string): Promise<NewsChannel>;
667669
}
668670

669-
export class BaseGuildVoiceChannel extends TextBasedChannelMixin(GuildChannel, true, [
670-
'lastPinTimestamp',
671-
'lastPinAt',
672-
]) {
671+
// tslint:disable-next-line no-empty-interface
672+
export interface BaseGuildVoiceChannel
673+
extends Omit<TextBasedChannelFields<true>, 'lastPinTimestamp' | 'lastPinAt'>,
674+
GuildChannel {}
675+
export class BaseGuildVoiceChannel extends GuildChannel {
673676
public constructor(guild: Guild, data?: RawGuildChannelData);
674677
public bitrate: number;
675678
public get full(): boolean;
@@ -1289,13 +1292,14 @@ export interface ResolvedFile {
12891292
contentType?: string;
12901293
}
12911294

1292-
export class DMChannel extends TextBasedChannelMixin(BaseChannel, false, [
1293-
'bulkDelete',
1294-
'fetchWebhooks',
1295-
'createWebhook',
1296-
'setRateLimitPerUser',
1297-
'setNSFW',
1298-
]) {
1295+
// tslint:disable-next-line no-empty-interface
1296+
export interface DMChannel
1297+
extends Omit<
1298+
TextBasedChannelFields<false>,
1299+
'bulkDelete' | 'fetchWebhooks' | 'createWebhook' | 'setRateLimitPerUser' | 'setNSFW'
1300+
>,
1301+
BaseChannel {}
1302+
export class DMChannel extends BaseChannel {
12991303
private constructor(client: Client<true>, data?: RawDMChannelData);
13001304
public flags: Readonly<ChannelFlagsBitField>;
13011305
public recipientId: Snowflake;
@@ -1574,7 +1578,8 @@ export class GuildMemberFlagsBitField extends BitField<GuildMemberFlagsString> {
15741578
public static resolve(bit?: BitFieldResolvable<GuildMemberFlagsString, GuildMemberFlags>): number;
15751579
}
15761580

1577-
export class GuildMember extends PartialTextBasedChannel(Base) {
1581+
export interface GuildMember extends PartialTextBasedChannelFields<false>, Base {}
1582+
export class GuildMember extends Base {
15781583
private constructor(client: Client<true>, data: RawGuildMemberData, guild: Guild);
15791584
private _roles: Snowflake[];
15801585
public avatar: string | null;
@@ -1925,7 +1930,9 @@ export class InteractionCollector<Interaction extends CollectedInteraction> exte
19251930
public once(event: string, listener: (...args: any[]) => void): this;
19261931
}
19271932

1928-
export class InteractionWebhook extends PartialWebhookMixin() {
1933+
// tslint:disable-next-line no-empty-interface
1934+
export interface InteractionWebhook extends PartialWebhookFields {}
1935+
export class InteractionWebhook {
19291936
public constructor(client: Client<true>, id: Snowflake, token: string);
19301937
public readonly client: Client<true>;
19311938
public token: string;
@@ -2469,17 +2476,21 @@ export interface DefaultReactionEmoji {
24692476
name: string | null;
24702477
}
24712478

2472-
export abstract class ThreadOnlyChannel extends TextBasedChannelMixin(GuildChannel, true, [
2473-
'send',
2474-
'lastMessage',
2475-
'lastPinAt',
2476-
'bulkDelete',
2477-
'sendTyping',
2478-
'createMessageCollector',
2479-
'awaitMessages',
2480-
'createMessageComponentCollector',
2481-
'awaitMessageComponent',
2482-
]) {
2479+
export interface ThreadOnlyChannel
2480+
extends Omit<
2481+
TextBasedChannelFields,
2482+
| 'send'
2483+
| 'lastMessage'
2484+
| 'lastPinAt'
2485+
| 'bulkDelete'
2486+
| 'sendTyping'
2487+
| 'createMessageCollector'
2488+
| 'awaitMessages'
2489+
| 'createMessageComponentCollector'
2490+
| 'awaitMessageComponent'
2491+
>,
2492+
GuildChannel {}
2493+
export abstract class ThreadOnlyChannel extends GuildChannel {
24832494
public type: ChannelType.GuildForum | ChannelType.GuildMedia;
24842495
public threads: GuildForumThreadManager;
24852496
public availableTags: GuildForumTag[];
@@ -3139,11 +3150,11 @@ export interface PrivateThreadChannel extends ThreadChannel<false> {
31393150
type: ChannelType.PrivateThread;
31403151
}
31413152

3142-
export class ThreadChannel<ThreadOnly extends boolean = boolean> extends TextBasedChannelMixin(BaseChannel, true, [
3143-
'fetchWebhooks',
3144-
'createWebhook',
3145-
'setNSFW',
3146-
]) {
3153+
// tslint:disable-next-line no-empty-interface
3154+
export interface ThreadChannel<ThreadOnly extends boolean = boolean>
3155+
extends Omit<TextBasedChannelFields<true>, 'fetchWebhooks' | 'createWebhook' | 'setNSFW'>,
3156+
BaseChannel {}
3157+
export class ThreadChannel<ThreadOnly extends boolean = boolean> extends BaseChannel {
31473158
private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client<true>);
31483159
public archived: boolean | null;
31493160
public get archivedAt(): Date | null;
@@ -3238,7 +3249,9 @@ export class Typing extends Base {
32383249
};
32393250
}
32403251

3241-
export class User extends PartialTextBasedChannel(Base) {
3252+
// tslint:disable-next-line no-empty-interface
3253+
export interface User extends PartialTextBasedChannelFields<false>, Base {}
3254+
export class User extends Base {
32423255
protected constructor(client: Client<true>, data: RawUserData);
32433256
private _equals(user: APIUser): boolean;
32443257

@@ -3491,7 +3504,9 @@ export class VoiceState extends Base {
34913504
public edit(options: VoiceStateEditOptions): Promise<this>;
34923505
}
34933506

3494-
export class Webhook extends WebhookMixin() {
3507+
// tslint:disable-next-line no-empty-interface
3508+
export interface Webhook extends WebhookFields {}
3509+
export class Webhook {
34953510
private constructor(client: Client<true>, data?: RawWebhookData);
34963511
public avatar: string | null;
34973512
public avatarURL(options?: ImageURLOptions): string | null;
@@ -3537,7 +3552,9 @@ export class Webhook extends WebhookMixin() {
35373552
public send(options: string | MessagePayload | WebhookMessageCreateOptions): Promise<Message>;
35383553
}
35393554

3540-
export class WebhookClient extends WebhookMixin(BaseClient) {
3555+
// tslint:disable-next-line no-empty-interface
3556+
export interface WebhookClient extends WebhookFields, BaseClient {}
3557+
export class WebhookClient extends BaseClient {
35413558
public constructor(data: WebhookClientData, options?: WebhookClientOptions);
35423559
public readonly client: this;
35433560
public options: WebhookClientOptions;
@@ -4485,22 +4502,6 @@ export class VoiceStateManager extends CachedManager<Snowflake, VoiceState, type
44854502

44864503
export type Constructable<Entity> = abstract new (...args: any[]) => Entity;
44874504

4488-
/** @internal */
4489-
export function PartialTextBasedChannel<Entity>(
4490-
Base?: Constructable<Entity>,
4491-
): Constructable<Entity & PartialTextBasedChannelFields<false>>;
4492-
4493-
/** @internal */
4494-
export function TextBasedChannelMixin<
4495-
Entity,
4496-
InGuild extends boolean = boolean,
4497-
IgnoredFields extends keyof TextBasedChannelFields<InGuild> = never,
4498-
>(
4499-
Base?: Constructable<Entity>,
4500-
inGuild?: InGuild,
4501-
ignore?: IgnoredFields[],
4502-
): Constructable<Entity & Omit<TextBasedChannelFields<InGuild>, IgnoredFields>>;
4503-
45044505
export interface PartialTextBasedChannelFields<InGuild extends boolean = boolean> {
45054506
send(options: string | MessagePayload | MessageCreateOptions): Promise<Message<InGuild>>;
45064507
}
@@ -4531,11 +4532,6 @@ export interface TextBasedChannelFields<InGuild extends boolean = boolean>
45314532
setNSFW(nsfw?: boolean, reason?: string): Promise<this>;
45324533
}
45334534

4534-
/** @internal */
4535-
export function PartialWebhookMixin<Entity>(Base?: Constructable<Entity>): Constructable<Entity & PartialWebhookFields>;
4536-
/** @internal */
4537-
export function WebhookMixin<Entity>(Base?: Constructable<Entity>): Constructable<Entity & WebhookFields>;
4538-
45394535
/** @internal */
45404536
export interface PartialWebhookFields {
45414537
id: Snowflake;

0 commit comments

Comments
 (0)
Please sign in to comment.