Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: replace Mixins with interface merging #10094

Merged
merged 5 commits into from
Feb 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 50 additions & 54 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,9 @@ export class BaseGuildEmoji extends Emoji {
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);
public defaultAutoArchiveDuration?: ThreadAutoArchiveDuration;
public defaultThreadRateLimitPerUser: number | null;
Expand All @@ -666,10 +668,11 @@ export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel, tr
public setType(type: ChannelType.GuildAnnouncement, reason?: string): Promise<NewsChannel>;
}

export class BaseGuildVoiceChannel extends TextBasedChannelMixin(GuildChannel, true, [
'lastPinTimestamp',
'lastPinAt',
]) {
// tslint:disable-next-line no-empty-interface
export interface BaseGuildVoiceChannel
extends Omit<TextBasedChannelFields<true>, 'lastPinTimestamp' | 'lastPinAt'>,
GuildChannel {}
export class BaseGuildVoiceChannel extends GuildChannel {
public constructor(guild: Guild, data?: RawGuildChannelData);
public bitrate: number;
public get full(): boolean;
Expand Down Expand Up @@ -1289,13 +1292,14 @@ export interface ResolvedFile {
contentType?: string;
}

export class DMChannel extends TextBasedChannelMixin(BaseChannel, false, [
'bulkDelete',
'fetchWebhooks',
'createWebhook',
'setRateLimitPerUser',
'setNSFW',
]) {
// tslint:disable-next-line no-empty-interface
export interface DMChannel
extends Omit<
TextBasedChannelFields<false>,
'bulkDelete' | 'fetchWebhooks' | 'createWebhook' | 'setRateLimitPerUser' | 'setNSFW'
>,
BaseChannel {}
export class DMChannel extends BaseChannel {
private constructor(client: Client<true>, data?: RawDMChannelData);
public flags: Readonly<ChannelFlagsBitField>;
public recipientId: Snowflake;
Expand Down Expand Up @@ -1574,7 +1578,8 @@ export class GuildMemberFlagsBitField extends BitField<GuildMemberFlagsString> {
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 _roles: Snowflake[];
public avatar: string | null;
Expand Down Expand Up @@ -1925,7 +1930,9 @@ export class InteractionCollector<Interaction extends CollectedInteraction> exte
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 readonly client: Client<true>;
public token: string;
Expand Down Expand Up @@ -2469,17 +2476,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[];
Expand Down Expand Up @@ -3139,11 +3150,11 @@ export interface PrivateThreadChannel extends ThreadChannel<false> {
type: ChannelType.PrivateThread;
}

export class ThreadChannel<ThreadOnly extends boolean = boolean> extends TextBasedChannelMixin(BaseChannel, true, [
'fetchWebhooks',
'createWebhook',
'setNSFW',
]) {
// tslint:disable-next-line no-empty-interface
export interface ThreadChannel<ThreadOnly extends boolean = boolean>
extends Omit<TextBasedChannelFields<true>, 'fetchWebhooks' | 'createWebhook' | 'setNSFW'>,
BaseChannel {}
export class ThreadChannel<ThreadOnly extends boolean = boolean> extends BaseChannel {
private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client<true>);
public archived: boolean | null;
public get archivedAt(): Date | null;
Expand Down Expand Up @@ -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);
private _equals(user: APIUser): boolean;

Expand Down Expand Up @@ -3491,7 +3504,9 @@ export class VoiceState extends Base {
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);
public avatar: string | null;
public avatarURL(options?: ImageURLOptions): string | null;
Expand Down Expand Up @@ -3537,7 +3552,9 @@ export class Webhook extends WebhookMixin() {
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 readonly client: this;
public options: WebhookClientOptions;
Expand Down Expand Up @@ -4485,22 +4502,6 @@ export class VoiceStateManager extends CachedManager<Snowflake, VoiceState, type

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> {
send(options: string | MessagePayload | MessageCreateOptions): Promise<Message<InGuild>>;
}
Expand Down Expand Up @@ -4531,11 +4532,6 @@ export interface TextBasedChannelFields<InGuild extends boolean = boolean>
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 */
export interface PartialWebhookFields {
id: Snowflake;
Expand Down
Loading