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

Add type safety to interface AuditLogChange #10437

Closed
OverwrittenCode opened this issue Aug 8, 2024 · 0 comments · Fixed by #10438
Closed

Add type safety to interface AuditLogChange #10437

OverwrittenCode opened this issue Aug 8, 2024 · 0 comments · Fixed by #10438

Comments

@OverwrittenCode
Copy link

Which application or package is this feature request for?

discord.js

Feature

When using the <GuildAuditLogsEntry>#changes inside Events.GuildAuditLogEntryCreate, the interface AuditLogChange does not have any type safety as it merges all the properties in the union of APIAuditLogChange together, which prevents the discriminator property AuditLogChange#key from narrowing down the types .

Ideal solution or implementation

Replace interface AuditLogChange with the below:

export type AuditLogChange = APIAuditLogChange extends infer U extends APIAuditLogChange
	? U extends U
		? {
				key: U["key"];
				old?: U["old_value"];
				new?: U["new_value"];
			}
		: never
	: never;

See typescript playground example

Alternative solutions or implementations

No response

Other context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant