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>
This commit is contained in:
Qjuh
2024-02-11 20:26:20 +01:00
committed by GitHub
parent ce6b2b74bc
commit 54106dbd81

View File

@@ -647,7 +647,9 @@ export class BaseGuildEmoji extends Emoji {
public requiresColons: boolean | null; public requiresColons: boolean | null;
} }
export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel, true) { // tslint:disable-next-line no-empty-interface
export interface BaseGuildTextChannel extends TextBasedChannelFields<true>, GuildChannel {}
export class BaseGuildTextChannel extends GuildChannel {
protected constructor(guild: Guild, data?: RawGuildChannelData, client?: Client<true>, immediatePatch?: boolean); protected constructor(guild: Guild, data?: RawGuildChannelData, client?: Client<true>, immediatePatch?: boolean);
public defaultAutoArchiveDuration?: ThreadAutoArchiveDuration; public defaultAutoArchiveDuration?: ThreadAutoArchiveDuration;
public defaultThreadRateLimitPerUser: number | null; public defaultThreadRateLimitPerUser: number | null;
@@ -666,10 +668,11 @@ export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel, tr
public setType(type: ChannelType.GuildAnnouncement, reason?: string): Promise<NewsChannel>; public setType(type: ChannelType.GuildAnnouncement, reason?: string): Promise<NewsChannel>;
} }
export class BaseGuildVoiceChannel extends TextBasedChannelMixin(GuildChannel, true, [ // tslint:disable-next-line no-empty-interface
'lastPinTimestamp', export interface BaseGuildVoiceChannel
'lastPinAt', extends Omit<TextBasedChannelFields<true>, 'lastPinTimestamp' | 'lastPinAt'>,
]) { GuildChannel {}
export class BaseGuildVoiceChannel extends GuildChannel {
public constructor(guild: Guild, data?: RawGuildChannelData); public constructor(guild: Guild, data?: RawGuildChannelData);
public bitrate: number; public bitrate: number;
public get full(): boolean; public get full(): boolean;
@@ -1289,13 +1292,14 @@ export interface ResolvedFile {
contentType?: string; contentType?: string;
} }
export class DMChannel extends TextBasedChannelMixin(BaseChannel, false, [ // tslint:disable-next-line no-empty-interface
'bulkDelete', export interface DMChannel
'fetchWebhooks', extends Omit<
'createWebhook', TextBasedChannelFields<false>,
'setRateLimitPerUser', 'bulkDelete' | 'fetchWebhooks' | 'createWebhook' | 'setRateLimitPerUser' | 'setNSFW'
'setNSFW', >,
]) { BaseChannel {}
export class DMChannel extends BaseChannel {
private constructor(client: Client<true>, data?: RawDMChannelData); private constructor(client: Client<true>, data?: RawDMChannelData);
public flags: Readonly<ChannelFlagsBitField>; public flags: Readonly<ChannelFlagsBitField>;
public recipientId: Snowflake; public recipientId: Snowflake;
@@ -1574,7 +1578,8 @@ export class GuildMemberFlagsBitField extends BitField<GuildMemberFlagsString> {
public static resolve(bit?: BitFieldResolvable<GuildMemberFlagsString, GuildMemberFlags>): number; public static resolve(bit?: BitFieldResolvable<GuildMemberFlagsString, GuildMemberFlags>): number;
} }
export class GuildMember extends PartialTextBasedChannel(Base) { export interface GuildMember extends PartialTextBasedChannelFields<false>, Base {}
export class GuildMember extends Base {
private constructor(client: Client<true>, data: RawGuildMemberData, guild: Guild); private constructor(client: Client<true>, data: RawGuildMemberData, guild: Guild);
private _roles: Snowflake[]; private _roles: Snowflake[];
public avatar: string | null; public avatar: string | null;
@@ -1925,7 +1930,9 @@ export class InteractionCollector<Interaction extends CollectedInteraction> exte
public once(event: string, listener: (...args: any[]) => void): this; public once(event: string, listener: (...args: any[]) => void): this;
} }
export class InteractionWebhook extends PartialWebhookMixin() { // tslint:disable-next-line no-empty-interface
export interface InteractionWebhook extends PartialWebhookFields {}
export class InteractionWebhook {
public constructor(client: Client<true>, id: Snowflake, token: string); public constructor(client: Client<true>, id: Snowflake, token: string);
public readonly client: Client<true>; public readonly client: Client<true>;
public token: string; public token: string;
@@ -2469,17 +2476,21 @@ export interface DefaultReactionEmoji {
name: string | null; name: string | null;
} }
export abstract class ThreadOnlyChannel extends TextBasedChannelMixin(GuildChannel, true, [ export interface ThreadOnlyChannel
'send', extends Omit<
'lastMessage', TextBasedChannelFields,
'lastPinAt', | 'send'
'bulkDelete', | 'lastMessage'
'sendTyping', | 'lastPinAt'
'createMessageCollector', | 'bulkDelete'
'awaitMessages', | 'sendTyping'
'createMessageComponentCollector', | 'createMessageCollector'
'awaitMessageComponent', | 'awaitMessages'
]) { | 'createMessageComponentCollector'
| 'awaitMessageComponent'
>,
GuildChannel {}
export abstract class ThreadOnlyChannel extends GuildChannel {
public type: ChannelType.GuildForum | ChannelType.GuildMedia; public type: ChannelType.GuildForum | ChannelType.GuildMedia;
public threads: GuildForumThreadManager; public threads: GuildForumThreadManager;
public availableTags: GuildForumTag[]; public availableTags: GuildForumTag[];
@@ -3139,11 +3150,11 @@ export interface PrivateThreadChannel extends ThreadChannel<false> {
type: ChannelType.PrivateThread; type: ChannelType.PrivateThread;
} }
export class ThreadChannel<ThreadOnly extends boolean = boolean> extends TextBasedChannelMixin(BaseChannel, true, [ // tslint:disable-next-line no-empty-interface
'fetchWebhooks', export interface ThreadChannel<ThreadOnly extends boolean = boolean>
'createWebhook', extends Omit<TextBasedChannelFields<true>, 'fetchWebhooks' | 'createWebhook' | 'setNSFW'>,
'setNSFW', BaseChannel {}
]) { export class ThreadChannel<ThreadOnly extends boolean = boolean> extends BaseChannel {
private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client<true>); private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client<true>);
public archived: boolean | null; public archived: boolean | null;
public get archivedAt(): Date | null; public get archivedAt(): Date | null;
@@ -3238,7 +3249,9 @@ export class Typing extends Base {
}; };
} }
export class User extends PartialTextBasedChannel(Base) { // tslint:disable-next-line no-empty-interface
export interface User extends PartialTextBasedChannelFields<false>, Base {}
export class User extends Base {
protected constructor(client: Client<true>, data: RawUserData); protected constructor(client: Client<true>, data: RawUserData);
private _equals(user: APIUser): boolean; private _equals(user: APIUser): boolean;
@@ -3491,7 +3504,9 @@ export class VoiceState extends Base {
public edit(options: VoiceStateEditOptions): Promise<this>; public edit(options: VoiceStateEditOptions): Promise<this>;
} }
export class Webhook extends WebhookMixin() { // tslint:disable-next-line no-empty-interface
export interface Webhook extends WebhookFields {}
export class Webhook {
private constructor(client: Client<true>, data?: RawWebhookData); private constructor(client: Client<true>, data?: RawWebhookData);
public avatar: string | null; public avatar: string | null;
public avatarURL(options?: ImageURLOptions): string | null; public avatarURL(options?: ImageURLOptions): string | null;
@@ -3537,7 +3552,9 @@ export class Webhook extends WebhookMixin() {
public send(options: string | MessagePayload | WebhookMessageCreateOptions): Promise<Message>; public send(options: string | MessagePayload | WebhookMessageCreateOptions): Promise<Message>;
} }
export class WebhookClient extends WebhookMixin(BaseClient) { // tslint:disable-next-line no-empty-interface
export interface WebhookClient extends WebhookFields, BaseClient {}
export class WebhookClient extends BaseClient {
public constructor(data: WebhookClientData, options?: WebhookClientOptions); public constructor(data: WebhookClientData, options?: WebhookClientOptions);
public readonly client: this; public readonly client: this;
public options: WebhookClientOptions; public options: WebhookClientOptions;
@@ -4485,22 +4502,6 @@ export class VoiceStateManager extends CachedManager<Snowflake, VoiceState, type
export type Constructable<Entity> = abstract new (...args: any[]) => Entity; export type Constructable<Entity> = abstract new (...args: any[]) => Entity;
/** @internal */
export function PartialTextBasedChannel<Entity>(
Base?: Constructable<Entity>,
): Constructable<Entity & PartialTextBasedChannelFields<false>>;
/** @internal */
export function TextBasedChannelMixin<
Entity,
InGuild extends boolean = boolean,
IgnoredFields extends keyof TextBasedChannelFields<InGuild> = never,
>(
Base?: Constructable<Entity>,
inGuild?: InGuild,
ignore?: IgnoredFields[],
): Constructable<Entity & Omit<TextBasedChannelFields<InGuild>, IgnoredFields>>;
export interface PartialTextBasedChannelFields<InGuild extends boolean = boolean> { export interface PartialTextBasedChannelFields<InGuild extends boolean = boolean> {
send(options: string | MessagePayload | MessageCreateOptions): Promise<Message<InGuild>>; send(options: string | MessagePayload | MessageCreateOptions): Promise<Message<InGuild>>;
} }
@@ -4531,11 +4532,6 @@ export interface TextBasedChannelFields<InGuild extends boolean = boolean>
setNSFW(nsfw?: boolean, reason?: string): Promise<this>; setNSFW(nsfw?: boolean, reason?: string): Promise<this>;
} }
/** @internal */
export function PartialWebhookMixin<Entity>(Base?: Constructable<Entity>): Constructable<Entity & PartialWebhookFields>;
/** @internal */
export function WebhookMixin<Entity>(Base?: Constructable<Entity>): Constructable<Entity & WebhookFields>;
/** @internal */ /** @internal */
export interface PartialWebhookFields { export interface PartialWebhookFields {
id: Snowflake; id: Snowflake;