Skip to content

Commit 72b8c83

Browse files
authored
fix: discriminated thread channel types (#1247)
1 parent b360b2e commit 72b8c83

File tree

6 files changed

+96
-48
lines changed

6 files changed

+96
-48
lines changed

deno/payloads/v10/channel.ts

Lines changed: 24 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deno/payloads/v9/auditLog.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deno/payloads/v9/channel.ts

Lines changed: 23 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

payloads/v10/channel.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ export interface APITextBasedChannel<T extends ChannelType> extends APIChannelBa
9898
rate_limit_per_user?: number;
9999
}
100100

101+
export interface APISortableChannel {
102+
/**
103+
* Sorting position of the channel
104+
*/
105+
position: number;
106+
}
107+
101108
export interface APIGuildChannel<T extends ChannelType> extends Omit<APIChannelBase<T>, 'name'> {
102109
/**
103110
* The name of the channel (1-100 characters)
@@ -113,10 +120,6 @@ export interface APIGuildChannel<T extends ChannelType> extends Omit<APIChannelB
113120
* @see {@link https://discord.com/developers/docs/resources/channel#overwrite-object}
114121
*/
115122
permission_overwrites?: APIOverwrite[];
116-
/**
117-
* Sorting position of the channel
118-
*/
119-
position: number;
120123
/**
121124
* ID of the parent category for a channel (each parent category can contain up to 50 channels)
122125
*
@@ -135,7 +138,8 @@ export type GuildTextChannelType = Exclude<TextChannelType, ChannelType.DM | Cha
135138

136139
export interface APIGuildTextChannel<T extends ChannelType.GuildForum | ChannelType.GuildMedia | GuildTextChannelType>
137140
extends Omit<APITextBasedChannel<T>, 'name'>,
138-
APIGuildChannel<T> {
141+
APIGuildChannel<T>,
142+
APISortableChannel {
139143
/**
140144
* Default duration for newly created threads, in minutes, to automatically archive the thread after recent activity
141145
*/
@@ -153,10 +157,11 @@ export interface APIGuildTextChannel<T extends ChannelType.GuildForum | ChannelT
153157

154158
export type APITextChannel = APIGuildTextChannel<ChannelType.GuildText>;
155159
export type APINewsChannel = APIGuildTextChannel<ChannelType.GuildAnnouncement>;
156-
export type APIGuildCategoryChannel = APIGuildChannel<ChannelType.GuildCategory>;
160+
export interface APIGuildCategoryChannel extends APIGuildChannel<ChannelType.GuildCategory>, APISortableChannel {}
157161

158162
export interface APIVoiceChannelBase<T extends ChannelType>
159163
extends APIGuildChannel<T>,
164+
APISortableChannel,
160165
Omit<APITextBasedChannel<T>, 'last_pin_timestamp' | 'name'> {
161166
/**
162167
* The bitrate (in bits) of the voice or stage channel
@@ -229,9 +234,9 @@ export interface APIGroupDMChannel extends Omit<APIDMChannelBase<ChannelType.Gro
229234

230235
export type ThreadChannelType = ChannelType.AnnouncementThread | ChannelType.PrivateThread | ChannelType.PublicThread;
231236

232-
export interface APIThreadChannel
233-
extends Omit<APITextBasedChannel<ThreadChannelType>, 'name'>,
234-
APIGuildChannel<ThreadChannelType> {
237+
export interface APIThreadChannel<Type extends ThreadChannelType = ThreadChannelType>
238+
extends Omit<APITextBasedChannel<Type>, 'name'>,
239+
APIGuildChannel<Type> {
235240
/**
236241
* The client users member for the thread, only included in select endpoints
237242
*/
@@ -266,6 +271,10 @@ export interface APIThreadChannel
266271
applied_tags: Snowflake[];
267272
}
268273

274+
export type APIPublicThreadChannel = APIThreadChannel<ChannelType.PublicThread>;
275+
export type APIPrivateThreadChannel = APIThreadChannel<ChannelType.PrivateThread>;
276+
export type APIAnnouncementThreadChannel = APIThreadChannel<ChannelType.AnnouncementThread>;
277+
269278
/**
270279
* @see {@link https://discord.com/developers/docs/resources/channel#forum-tag-object-forum-tag-structure}
271280
*/
@@ -339,7 +348,8 @@ export enum ForumLayoutType {
339348
}
340349

341350
export interface APIThreadOnlyChannel<T extends ChannelType.GuildForum | ChannelType.GuildMedia>
342-
extends APIGuildChannel<T> {
351+
extends APIGuildChannel<T>,
352+
APISortableChannel {
343353
/**
344354
* The channel topic (0-4096 characters)
345355
*/
@@ -398,6 +408,7 @@ export type APIGuildMediaChannel = APIThreadOnlyChannel<ChannelType.GuildMedia>;
398408
* @see {@link https://discord.com/developers/docs/resources/channel#channel-object-channel-structure}
399409
*/
400410
export type APIChannel =
411+
| APIAnnouncementThreadChannel
401412
| APIDMChannel
402413
| APIGroupDMChannel
403414
| APIGuildCategoryChannel
@@ -406,8 +417,9 @@ export type APIChannel =
406417
| APIGuildStageVoiceChannel
407418
| APIGuildVoiceChannel
408419
| APINewsChannel
409-
| APITextChannel
410-
| APIThreadChannel;
420+
| APIPrivateThreadChannel
421+
| APIPublicThreadChannel
422+
| APITextChannel;
411423

412424
/**
413425
* @see {@link https://discord.com/developers/docs/resources/channel#channel-object-channel-types}

payloads/v9/auditLog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export interface APIAuditLogOptions {
325325
* - CHANNEL_OVERWRITE_UPDATE
326326
* - CHANNEL_OVERWRITE_DELETE
327327
*
328-
* **Present only if the {@link APIAuditLogOptions.type | entry type} is "0"**
328+
* **Present only if the {@link APIAuditLogOptions."type" | entry type} is "0"**
329329
*/
330330
role_name?: string;
331331

0 commit comments

Comments
 (0)