Skip to content

Commit

Permalink
Merge branch 'main' into fix/widget-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Aug 21, 2022
2 parents a76bd65 + b3f7c32 commit 162b94b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/discord.js/src/managers/GuildChannelManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class GuildChannelManager extends CachedManager {

/**
* @typedef {ChannelWebhookCreateOptions} WebhookCreateOptions
* @property {GuildChannelResolvable} channel The channel to create the webhook for
* @property {TextChannel|NewsChannel|VoiceChannel|Snowflake} channel The channel to create the webhook for
*/

/**
Expand Down
1 change: 0 additions & 1 deletion packages/discord.js/src/structures/GuildAuditLogsEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ class GuildAuditLogsEntry {
case AuditLogEvent.ApplicationCommandPermissionUpdate:
this.extra = {
applicationId: data.options.application_id,
guild: guild.client.guilds.cache.get(data.options.guild_id) ?? { id: data.options.guild_id },
};
break;

Expand Down
49 changes: 27 additions & 22 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ declare module 'node:events' {
class EventEmitter {
// Add type overloads for client events.
public static once<K extends keyof ClientEvents>(eventEmitter: Client, eventName: K): Promise<ClientEvents[K]>;
public static on<K extends keyof ClientEvents>(eventEmitter: Client, eventName: K): AsyncIterator<ClientEvents[K]>;
public static on<K extends keyof ClientEvents>(
eventEmitter: Client,
eventName: K,
): AsyncIterableIterator<ClientEvents[K]>;
}
}

Expand Down Expand Up @@ -1178,35 +1181,37 @@ export class Guild extends AnonymousGuild {
public toJSON(): unknown;
}

export class GuildAuditLogs<T extends GuildAuditLogsResolvable = null> {
export class GuildAuditLogs<T extends GuildAuditLogsResolvable = AuditLogEvent> {
private constructor(guild: Guild, data: RawGuildAuditLogData);
private applicationCommands: Collection<Snowflake, ApplicationCommand>;
private webhooks: Collection<Snowflake, Webhook>;
private integrations: Collection<Snowflake | string, Integration>;
private guildScheduledEvents: Collection<Snowflake, GuildScheduledEvent>;
public entries: Collection<Snowflake, GuildAuditLogsEntry<T>>;
public static Entry: typeof GuildAuditLogsEntry;
public toJSON(): unknown;
}

export class GuildAuditLogsEntry<
TAction extends GuildAuditLogsResolvable = null,
TAction extends GuildAuditLogsResolvable = AuditLogEvent,
TActionType extends GuildAuditLogsActionType = TAction extends keyof GuildAuditLogsTypes
? GuildAuditLogsTypes[TAction][1]
: 'All',
: GuildAuditLogsActionType,
TTargetType extends GuildAuditLogsTargetType = TAction extends keyof GuildAuditLogsTypes
? GuildAuditLogsTypes[TAction][0]
: 'Unknown',
: GuildAuditLogsTargetType,
TResolvedType = TAction extends null ? AuditLogEvent : TAction,
> {
private constructor(logs: GuildAuditLogs, guild: Guild, data: RawGuildAuditLogEntryData);
public static Targets: GuildAuditLogsTargets;
public action: TAction;
public action: TResolvedType;
public actionType: TActionType;
public changes: AuditLogChange[];
public get createdAt(): Date;
public get createdTimestamp(): number;
public executor: User | null;
public extra: TAction extends keyof GuildAuditLogsEntryExtraField ? GuildAuditLogsEntryExtraField[TAction] : null;
public extra: TResolvedType extends keyof GuildAuditLogsEntryExtraField
? GuildAuditLogsEntryExtraField[TResolvedType]
: null;
public id: Snowflake;
public reason: string | null;
public target: TTargetType extends keyof GuildAuditLogsEntryTargetField<TActionType>
Expand Down Expand Up @@ -3868,27 +3873,29 @@ export interface ApplicationCommandAutocompleteStringOptionData
autocomplete: true;
}

export interface ApplicationCommandChoicesData extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
export interface ApplicationCommandChoicesData<Type extends string | number = string | number>
extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
type: CommandOptionChoiceResolvableType;
choices?: ApplicationCommandOptionChoiceData[];
choices?: ApplicationCommandOptionChoiceData<Type>[];
autocomplete?: false;
}

export interface ApplicationCommandChoicesOption extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
export interface ApplicationCommandChoicesOption<Type extends string | number = string | number>
extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> {
type: CommandOptionChoiceResolvableType;
choices?: ApplicationCommandOptionChoiceData[];
choices?: ApplicationCommandOptionChoiceData<Type>[];
autocomplete?: false;
}

export interface ApplicationCommandNumericOptionData extends ApplicationCommandChoicesData {
export interface ApplicationCommandNumericOptionData extends ApplicationCommandChoicesData<number> {
type: CommandOptionNumericResolvableType;
minValue?: number;
min_value?: number;
maxValue?: number;
max_value?: number;
}

export interface ApplicationCommandStringOptionData extends ApplicationCommandChoicesData {
export interface ApplicationCommandStringOptionData extends ApplicationCommandChoicesData<string> {
type: ApplicationCommandOptionType.String;
minLength?: number;
min_length?: number;
Expand All @@ -3900,13 +3907,13 @@ export interface ApplicationCommandBooleanOptionData extends BaseApplicationComm
type: ApplicationCommandOptionType.Boolean;
}

export interface ApplicationCommandNumericOption extends ApplicationCommandChoicesOption {
export interface ApplicationCommandNumericOption extends ApplicationCommandChoicesOption<number> {
type: CommandOptionNumericResolvableType;
minValue?: number;
maxValue?: number;
}

export interface ApplicationCommandStringOption extends ApplicationCommandChoicesOption {
export interface ApplicationCommandStringOption extends ApplicationCommandChoicesOption<string> {
type: ApplicationCommandOptionType.String;
minLength?: number;
maxLength?: number;
Expand Down Expand Up @@ -3948,7 +3955,6 @@ export type ApplicationCommandOptionData =
| ApplicationCommandSubGroupData
| ApplicationCommandNonOptionsData
| ApplicationCommandChannelOptionData
| ApplicationCommandChoicesData
| ApplicationCommandAutocompleteNumericOptionData
| ApplicationCommandAutocompleteStringOptionData
| ApplicationCommandNumericOptionData
Expand All @@ -3965,7 +3971,6 @@ export type ApplicationCommandOption =
| ApplicationCommandAutocompleteStringOption
| ApplicationCommandNonOptions
| ApplicationCommandChannelOption
| ApplicationCommandChoicesOption
| ApplicationCommandNumericOption
| ApplicationCommandStringOption
| ApplicationCommandRoleOption
Expand All @@ -3975,10 +3980,10 @@ export type ApplicationCommandOption =
| ApplicationCommandAttachmentOption
| ApplicationCommandSubCommand;

export interface ApplicationCommandOptionChoiceData {
export interface ApplicationCommandOptionChoiceData<Value extends string | number = string | number> {
name: string;
nameLocalizations?: LocalizationMap;
value: string | number;
value: Value;
}

export interface ApplicationCommandPermissions {
Expand Down Expand Up @@ -4152,7 +4157,7 @@ export interface ChannelWebhookCreateOptions {
}

export interface WebhookCreateOptions extends ChannelWebhookCreateOptions {
channel: GuildChannelResolvable;
channel: TextChannel | NewsChannel | VoiceChannel | Snowflake;
}

export interface ClientEvents {
Expand Down Expand Up @@ -4733,7 +4738,7 @@ export interface GuildAuditLogsEntryExtraField {
[AuditLogEvent.StageInstanceCreate]: StageChannel | { id: Snowflake };
[AuditLogEvent.StageInstanceDelete]: StageChannel | { id: Snowflake };
[AuditLogEvent.StageInstanceUpdate]: StageChannel | { id: Snowflake };
[AuditLogEvent.ApplicationCommandPermissionUpdate]: { applicationId: Snowflake; guild: Guild | { id: Snowflake } };
[AuditLogEvent.ApplicationCommandPermissionUpdate]: { applicationId: Snowflake };
}

export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLogsActionType> {
Expand Down
27 changes: 24 additions & 3 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ import {
Webhook,
WebhookClient,
InteractionWebhook,
GuildAuditLogsActionType,
GuildAuditLogsTargetType,
} from '.';
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
Expand Down Expand Up @@ -1100,6 +1102,7 @@ expectAssignable<'death'>(ShardEvents.Death);
expectAssignable<1>(Status.Connecting);

declare const applicationCommandData: ApplicationCommandData;
declare const applicationCommandOptionData: ApplicationCommandOptionData;
declare const applicationCommandResolvable: ApplicationCommandResolvable;
declare const applicationCommandManager: ApplicationCommandManager;
{
Expand All @@ -1119,6 +1122,24 @@ declare const applicationCommandManager: ApplicationCommandManager;
expectType<Promise<Collection<Snowflake, ApplicationCommand>>>(
applicationCommandManager.set([applicationCommandData], '0'),
);

// Test inference of choice values.
if ('choices' in applicationCommandOptionData) {
if (applicationCommandOptionData.type === ApplicationCommandOptionType.String) {
expectType<string>(applicationCommandOptionData.choices[0]!.value);
expectNotType<number>(applicationCommandOptionData.choices[0]!.value);
}

if (applicationCommandOptionData.type === ApplicationCommandOptionType.Integer) {
expectType<number>(applicationCommandOptionData.choices[0]!.value);
expectNotType<string>(applicationCommandOptionData.choices[0]!.value);
}

if (applicationCommandOptionData.type === ApplicationCommandOptionType.Number) {
expectType<number>(applicationCommandOptionData.choices[0]!.value);
expectNotType<string>(applicationCommandOptionData.choices[0]!.value);
}
}
}

declare const applicationNonChoiceOptionData: ApplicationCommandOptionData & {
Expand Down Expand Up @@ -1533,7 +1554,7 @@ expectType<Promise<GuildAuditLogs<AuditLogEvent.IntegrationUpdate>>>(
);

expectType<Promise<GuildAuditLogs<null>>>(guild.fetchAuditLogs({ type: null }));
expectType<Promise<GuildAuditLogs<null>>>(guild.fetchAuditLogs());
expectType<Promise<GuildAuditLogs<AuditLogEvent>>>(guild.fetchAuditLogs());

expectType<Promise<GuildAuditLogsEntry<AuditLogEvent.MemberKick, 'Delete', 'User'> | undefined>>(
guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick }).then(al => al.entries.first()),
Expand All @@ -1542,10 +1563,10 @@ expectAssignable<Promise<GuildAuditLogsEntry<AuditLogEvent.MemberKick, 'Delete',
guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick }).then(al => al.entries.first()),
);

expectType<Promise<GuildAuditLogsEntry<null, 'All', 'Unknown'> | undefined>>(
expectType<Promise<GuildAuditLogsEntry<null, GuildAuditLogsActionType, GuildAuditLogsTargetType> | undefined>>(
guild.fetchAuditLogs({ type: null }).then(al => al.entries.first()),
);
expectType<Promise<GuildAuditLogsEntry<null, 'All', 'Unknown'> | undefined>>(
expectType<Promise<GuildAuditLogsEntry<null, GuildAuditLogsActionType, GuildAuditLogsTargetType> | undefined>>(
guild.fetchAuditLogs().then(al => al.entries.first()),
);

Expand Down

0 comments on commit 162b94b

Please sign in to comment.