Skip to content

Commit

Permalink
fix(GatewayThreadDispatch): properly type thread create/update/delete…
Browse files Browse the repository at this point in the history
… dispatches (#861)

* fix: properly type thread create/update/delete dispatches

* fix(GatewayThreadDispatch): deno types

* fix(GatewayThreadDispatch): deprecate GatewayThreadModifyDispatch
  • Loading branch information
Saghetti0 committed Dec 27, 2023
1 parent 7f797b2 commit 819d852
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 24 deletions.
47 changes: 41 additions & 6 deletions deno/gateway/v10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
AutoModerationRuleTriggerType,
APIAuditLogEntry,
APIEntitlement,
ChannelType,
} from '../payloads/v10/mod.ts';
import type { Nullable } from '../utils/internals.ts';

Expand Down Expand Up @@ -339,7 +340,9 @@ export type GatewayDispatchPayload =
| GatewayThreadListSyncDispatch
| GatewayThreadMembersUpdateDispatch
| GatewayThreadMemberUpdateDispatch
| GatewayThreadModifyDispatch
| GatewayThreadCreateDispatch
| GatewayThreadUpdateDispatch
| GatewayThreadDeleteDispatch
| GatewayTypingStartDispatch
| GatewayUserUpdateDispatch
| GatewayVoiceServerUpdateDispatch
Expand Down Expand Up @@ -1608,6 +1611,10 @@ export type GatewayThreadMemberUpdateDispatch = DataPayload<
export type GatewayThreadMemberUpdateDispatchData = APIThreadMember & { guild_id: Snowflake };

/**
* @deprecated This type doesn't accurately reflect the Discord API.
* Use {@apilink GatewayThreadCreateDispatch},
* {@apilink GatewayThreadUpdateDispatch}, or
* {@apilink GatewayThreadDeleteDispatch} instead.
* https://discord.com/developers/docs/topics/gateway-events#thread-create
* https://discord.com/developers/docs/topics/gateway-events#thread-update
* https://discord.com/developers/docs/topics/gateway-events#thread-delete
Expand All @@ -1620,7 +1627,10 @@ export type GatewayThreadModifyDispatch = DataPayload<
/**
* https://discord.com/developers/docs/topics/gateway-events#thread-create
*/
export type GatewayThreadCreateDispatch = GatewayChannelModifyDispatch;
export type GatewayThreadCreateDispatch = DataPayload<
GatewayDispatchEvents.ThreadCreate,
GatewayThreadCreateDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-create
Expand All @@ -1635,22 +1645,47 @@ export interface GatewayThreadCreateDispatchData extends APIThreadChannel {
/**
* https://discord.com/developers/docs/topics/gateway-events#thread-update
*/
export type GatewayThreadUpdateDispatch = GatewayChannelModifyDispatch;
export type GatewayThreadUpdateDispatch = DataPayload<
GatewayDispatchEvents.ThreadUpdate,
GatewayThreadUpdateDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-update
*/
export type GatewayThreadUpdateDispatchData = GatewayChannelModifyDispatchData;
export type GatewayThreadUpdateDispatchData = APIThreadChannel;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-delete
*/
export type GatewayThreadDeleteDispatch = GatewayChannelModifyDispatch;
export type GatewayThreadDeleteDispatch = DataPayload<
GatewayDispatchEvents.ThreadDelete,
GatewayThreadDeleteDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-delete
*/
export type GatewayThreadDeleteDispatchData = GatewayChannelModifyDispatchData;
export interface GatewayThreadDeleteDispatchData {
/**
* The id of the channel
*/
id: Snowflake;
/**
* The id of the guild
*/
guild_id: Snowflake;
/**
* The id of the parent channel of the thread
*/
parent_id: Snowflake;
/**
* The type of the channel
*
* See https://discord.com/developers/docs/resources/channel#channel-object-channel-types
*/
type: ChannelType;
}

/**
* https://discord.com/developers/docs/topics/gateway-events#typing-start
Expand Down
47 changes: 41 additions & 6 deletions deno/gateway/v9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {
PresenceUpdateStatus,
AutoModerationRuleTriggerType,
APIAuditLogEntry,
ChannelType,
} from '../payloads/v9/mod.ts';
import type { Nullable } from '../utils/internals.ts';
import type { APIEntitlement } from '../v10.ts';
Expand Down Expand Up @@ -338,7 +339,9 @@ export type GatewayDispatchPayload =
| GatewayThreadListSyncDispatch
| GatewayThreadMembersUpdateDispatch
| GatewayThreadMemberUpdateDispatch
| GatewayThreadModifyDispatch
| GatewayThreadCreateDispatch
| GatewayThreadUpdateDispatch
| GatewayThreadDeleteDispatch
| GatewayTypingStartDispatch
| GatewayUserUpdateDispatch
| GatewayVoiceServerUpdateDispatch
Expand Down Expand Up @@ -1607,6 +1610,10 @@ export type GatewayThreadMemberUpdateDispatch = DataPayload<
export type GatewayThreadMemberUpdateDispatchData = APIThreadMember & { guild_id: Snowflake };

/**
* @deprecated This type doesn't accurately reflect the Discord API.
* Use {@apilink GatewayThreadCreateDispatch},
* {@apilink GatewayThreadUpdateDispatch}, or
* {@apilink GatewayThreadDeleteDispatch} instead.
* https://discord.com/developers/docs/topics/gateway-events#thread-create
* https://discord.com/developers/docs/topics/gateway-events#thread-update
* https://discord.com/developers/docs/topics/gateway-events#thread-delete
Expand All @@ -1619,7 +1626,10 @@ export type GatewayThreadModifyDispatch = DataPayload<
/**
* https://discord.com/developers/docs/topics/gateway-events#thread-create
*/
export type GatewayThreadCreateDispatch = GatewayChannelModifyDispatch;
export type GatewayThreadCreateDispatch = DataPayload<
GatewayDispatchEvents.ThreadCreate,
GatewayThreadCreateDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-create
Expand All @@ -1634,22 +1644,47 @@ export interface GatewayThreadCreateDispatchData extends APIThreadChannel {
/**
* https://discord.com/developers/docs/topics/gateway-events#thread-update
*/
export type GatewayThreadUpdateDispatch = GatewayChannelModifyDispatch;
export type GatewayThreadUpdateDispatch = DataPayload<
GatewayDispatchEvents.ThreadUpdate,
GatewayThreadUpdateDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-update
*/
export type GatewayThreadUpdateDispatchData = GatewayChannelModifyDispatchData;
export type GatewayThreadUpdateDispatchData = APIThreadChannel;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-delete
*/
export type GatewayThreadDeleteDispatch = GatewayChannelModifyDispatch;
export type GatewayThreadDeleteDispatch = DataPayload<
GatewayDispatchEvents.ThreadDelete,
GatewayThreadDeleteDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-delete
*/
export type GatewayThreadDeleteDispatchData = GatewayChannelModifyDispatchData;
export interface GatewayThreadDeleteDispatchData {
/**
* The id of the channel
*/
id: Snowflake;
/**
* The id of the guild
*/
guild_id: Snowflake;
/**
* The id of the parent channel of the thread
*/
parent_id: Snowflake;
/**
* The type of the channel
*
* See https://discord.com/developers/docs/resources/channel#channel-object-channel-types
*/
type: ChannelType;
}

/**
* https://discord.com/developers/docs/topics/gateway-events#typing-start
Expand Down
47 changes: 41 additions & 6 deletions gateway/v10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
AutoModerationRuleTriggerType,
APIAuditLogEntry,
APIEntitlement,
ChannelType,
} from '../payloads/v10/index';
import type { Nullable } from '../utils/internals';

Expand Down Expand Up @@ -339,7 +340,9 @@ export type GatewayDispatchPayload =
| GatewayThreadListSyncDispatch
| GatewayThreadMembersUpdateDispatch
| GatewayThreadMemberUpdateDispatch
| GatewayThreadModifyDispatch
| GatewayThreadCreateDispatch
| GatewayThreadUpdateDispatch
| GatewayThreadDeleteDispatch
| GatewayTypingStartDispatch
| GatewayUserUpdateDispatch
| GatewayVoiceServerUpdateDispatch
Expand Down Expand Up @@ -1608,6 +1611,10 @@ export type GatewayThreadMemberUpdateDispatch = DataPayload<
export type GatewayThreadMemberUpdateDispatchData = APIThreadMember & { guild_id: Snowflake };

/**
* @deprecated This type doesn't accurately reflect the Discord API.
* Use {@apilink GatewayThreadCreateDispatch},
* {@apilink GatewayThreadUpdateDispatch}, or
* {@apilink GatewayThreadDeleteDispatch} instead.
* https://discord.com/developers/docs/topics/gateway-events#thread-create
* https://discord.com/developers/docs/topics/gateway-events#thread-update
* https://discord.com/developers/docs/topics/gateway-events#thread-delete
Expand All @@ -1620,7 +1627,10 @@ export type GatewayThreadModifyDispatch = DataPayload<
/**
* https://discord.com/developers/docs/topics/gateway-events#thread-create
*/
export type GatewayThreadCreateDispatch = GatewayChannelModifyDispatch;
export type GatewayThreadCreateDispatch = DataPayload<
GatewayDispatchEvents.ThreadCreate,
GatewayThreadCreateDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-create
Expand All @@ -1635,22 +1645,47 @@ export interface GatewayThreadCreateDispatchData extends APIThreadChannel {
/**
* https://discord.com/developers/docs/topics/gateway-events#thread-update
*/
export type GatewayThreadUpdateDispatch = GatewayChannelModifyDispatch;
export type GatewayThreadUpdateDispatch = DataPayload<
GatewayDispatchEvents.ThreadUpdate,
GatewayThreadUpdateDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-update
*/
export type GatewayThreadUpdateDispatchData = GatewayChannelModifyDispatchData;
export type GatewayThreadUpdateDispatchData = APIThreadChannel;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-delete
*/
export type GatewayThreadDeleteDispatch = GatewayChannelModifyDispatch;
export type GatewayThreadDeleteDispatch = DataPayload<
GatewayDispatchEvents.ThreadDelete,
GatewayThreadDeleteDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-delete
*/
export type GatewayThreadDeleteDispatchData = GatewayChannelModifyDispatchData;
export interface GatewayThreadDeleteDispatchData {
/**
* The id of the channel
*/
id: Snowflake;
/**
* The id of the guild
*/
guild_id: Snowflake;
/**
* The id of the parent channel of the thread
*/
parent_id: Snowflake;
/**
* The type of the channel
*
* See https://discord.com/developers/docs/resources/channel#channel-object-channel-types
*/
type: ChannelType;
}

/**
* https://discord.com/developers/docs/topics/gateway-events#typing-start
Expand Down
47 changes: 41 additions & 6 deletions gateway/v9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {
PresenceUpdateStatus,
AutoModerationRuleTriggerType,
APIAuditLogEntry,
ChannelType,
} from '../payloads/v9/index';
import type { Nullable } from '../utils/internals';
import type { APIEntitlement } from '../v10';
Expand Down Expand Up @@ -338,7 +339,9 @@ export type GatewayDispatchPayload =
| GatewayThreadListSyncDispatch
| GatewayThreadMembersUpdateDispatch
| GatewayThreadMemberUpdateDispatch
| GatewayThreadModifyDispatch
| GatewayThreadCreateDispatch
| GatewayThreadUpdateDispatch
| GatewayThreadDeleteDispatch
| GatewayTypingStartDispatch
| GatewayUserUpdateDispatch
| GatewayVoiceServerUpdateDispatch
Expand Down Expand Up @@ -1607,6 +1610,10 @@ export type GatewayThreadMemberUpdateDispatch = DataPayload<
export type GatewayThreadMemberUpdateDispatchData = APIThreadMember & { guild_id: Snowflake };

/**
* @deprecated This type doesn't accurately reflect the Discord API.
* Use {@apilink GatewayThreadCreateDispatch},
* {@apilink GatewayThreadUpdateDispatch}, or
* {@apilink GatewayThreadDeleteDispatch} instead.
* https://discord.com/developers/docs/topics/gateway-events#thread-create
* https://discord.com/developers/docs/topics/gateway-events#thread-update
* https://discord.com/developers/docs/topics/gateway-events#thread-delete
Expand All @@ -1619,7 +1626,10 @@ export type GatewayThreadModifyDispatch = DataPayload<
/**
* https://discord.com/developers/docs/topics/gateway-events#thread-create
*/
export type GatewayThreadCreateDispatch = GatewayChannelModifyDispatch;
export type GatewayThreadCreateDispatch = DataPayload<
GatewayDispatchEvents.ThreadCreate,
GatewayThreadCreateDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-create
Expand All @@ -1634,22 +1644,47 @@ export interface GatewayThreadCreateDispatchData extends APIThreadChannel {
/**
* https://discord.com/developers/docs/topics/gateway-events#thread-update
*/
export type GatewayThreadUpdateDispatch = GatewayChannelModifyDispatch;
export type GatewayThreadUpdateDispatch = DataPayload<
GatewayDispatchEvents.ThreadUpdate,
GatewayThreadUpdateDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-update
*/
export type GatewayThreadUpdateDispatchData = GatewayChannelModifyDispatchData;
export type GatewayThreadUpdateDispatchData = APIThreadChannel;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-delete
*/
export type GatewayThreadDeleteDispatch = GatewayChannelModifyDispatch;
export type GatewayThreadDeleteDispatch = DataPayload<
GatewayDispatchEvents.ThreadDelete,
GatewayThreadDeleteDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#thread-delete
*/
export type GatewayThreadDeleteDispatchData = GatewayChannelModifyDispatchData;
export interface GatewayThreadDeleteDispatchData {
/**
* The id of the channel
*/
id: Snowflake;
/**
* The id of the guild
*/
guild_id: Snowflake;
/**
* The id of the parent channel of the thread
*/
parent_id: Snowflake;
/**
* The type of the channel
*
* See https://discord.com/developers/docs/resources/channel#channel-object-channel-types
*/
type: ChannelType;
}

/**
* https://discord.com/developers/docs/topics/gateway-events#typing-start
Expand Down

1 comment on commit 819d852

@vercel
Copy link

@vercel vercel bot commented on 819d852 Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.