-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Interface to associate GatewayDispatchEvents and relevant DataPayload (proposed code below) #617
Comments
I've actually had the need for this myself and simply hacked it up: import type { GatewayDispatchEvents, GatewayDispatchPayload, GatewaySendPayload } from 'discord-api-types/v10';
type _DiscordEventsMap = {
[K in GatewayDispatchEvents]: GatewayDispatchPayload & {
t: K;
};
};
export type DiscordEventsMap = {
// @ts-expect-error
[K in keyof _DiscordEventsMap]: _DiscordEventsMap[K]['d'];
} & {
send: GatewaySendPayload;
}; It doesn't play nicely with TSC, given the needed |
The reason your hack requires type _Payload = {
[E in GatewayDispatchEvents]: GatewayDispatchPayload & { t: E }
}
type GatewayDispatchData = {
[E in keyof _Payload]: "d" extends keyof _Payload[E] ? _Payload[E]["d"] : never
} I edited my original post to include it as an alternative implementation. |
Good catch! That explains why it only recently started occurring, thanks. |
Thats quite a big issue if there's events without associated payloads... PRs are more than welcome!! |
Done. (#619) |
Feature
A good addition would be an interface to associate a GatewayDispatchEvents event with the relevant DataPayload dispatched along this event.
Ideal solution or implementation
The following interface only works for V10 :
Alternative solutions or implementations
Other context
No response
The text was updated successfully, but these errors were encountered: