mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(GuildAuditLogsEntry): correct mapped AuditLogChange objects (#10438)
* refactor(GuildAuditLogsEntry): correct mapped AuditLogChange objects * test: check union narrowing behaviour of AuditLogChange --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -172,7 +172,11 @@ class GuildAuditLogsEntry {
|
||||
* @type {AuditLogChange[]}
|
||||
*/
|
||||
this.changes =
|
||||
data.changes?.map(change => ({ key: change.key, old: change.old_value, new: change.new_value })) ?? [];
|
||||
data.changes?.map(change => ({
|
||||
key: change.key,
|
||||
...('old_value' in change ? { old: change.old_value } : {}),
|
||||
...('new_value' in change ? { new: change.new_value } : {}),
|
||||
})) ?? [];
|
||||
|
||||
/**
|
||||
* The entry's id
|
||||
|
||||
12
packages/discord.js/typings/index.d.ts
vendored
12
packages/discord.js/typings/index.d.ts
vendored
@@ -4991,11 +4991,13 @@ export interface ApplicationRoleConnectionMetadataEditOptions {
|
||||
type: ApplicationRoleConnectionMetadataType;
|
||||
}
|
||||
|
||||
export interface AuditLogChange {
|
||||
key: APIAuditLogChange['key'];
|
||||
old?: APIAuditLogChange['old_value'];
|
||||
new?: APIAuditLogChange['new_value'];
|
||||
}
|
||||
export type AuditLogChange = {
|
||||
[SourceElement in APIAuditLogChange as SourceElement['key']]: {
|
||||
key: SourceElement['key'];
|
||||
old?: SourceElement['old_value'];
|
||||
new?: SourceElement['new_value'];
|
||||
};
|
||||
}[APIAuditLogChange['key']];
|
||||
|
||||
export interface AutoModerationAction {
|
||||
type: AutoModerationActionType;
|
||||
|
||||
@@ -104,6 +104,7 @@ import {
|
||||
Collector,
|
||||
GuildAuditLogsEntry,
|
||||
GuildAuditLogs,
|
||||
type AuditLogChange,
|
||||
StageInstance,
|
||||
ActionRowBuilder,
|
||||
ButtonComponent,
|
||||
@@ -2171,6 +2172,16 @@ expectType<Promise<User | undefined>>(
|
||||
guild.fetchAuditLogs({ type: AuditLogEvent.MessageDelete }).then(al => al.entries.first()?.target),
|
||||
);
|
||||
|
||||
declare const AuditLogChange: AuditLogChange;
|
||||
// @ts-expect-error
|
||||
expectType<boolean | undefined>(AuditLogChange.old);
|
||||
// @ts-expect-error
|
||||
expectType<boolean | undefined>(AuditLogChange.new);
|
||||
if (AuditLogChange.key === 'available') {
|
||||
expectType<boolean | undefined>(AuditLogChange.old);
|
||||
expectType<boolean | undefined>(AuditLogChange.new);
|
||||
}
|
||||
|
||||
declare const TextBasedChannel: TextBasedChannel;
|
||||
declare const TextBasedChannelTypes: TextBasedChannelTypes;
|
||||
declare const VoiceBasedChannel: VoiceBasedChannel;
|
||||
|
||||
Reference in New Issue
Block a user