From 995126e2cc1494f9fad2ad7c44ecc87898994e44 Mon Sep 17 00:00:00 2001 From: Cynthia Date: Sun, 11 Dec 2022 21:48:02 +0100 Subject: [PATCH] fix(APIChannel): correctly type `name` based on channel type (#666) Co-authored-by: Vlad Frangu --- deno/payloads/v10/channel.ts | 29 +++++++++++++++++++---------- deno/payloads/v9/channel.ts | 29 +++++++++++++++++++---------- payloads/v10/channel.ts | 29 +++++++++++++++++++---------- payloads/v9/channel.ts | 29 +++++++++++++++++++---------- tests/v10/channel.test-d.ts | 14 ++++++++++++++ 5 files changed, 90 insertions(+), 40 deletions(-) create mode 100644 tests/v10/channel.test-d.ts diff --git a/deno/payloads/v10/channel.ts b/deno/payloads/v10/channel.ts index ee2f7d52..a37218c8 100644 --- a/deno/payloads/v10/channel.ts +++ b/deno/payloads/v10/channel.ts @@ -25,9 +25,9 @@ export interface APIPartialChannel { */ type: ChannelType; /** - * The name of the channel (2-100 characters) + * The name of the channel (1-100 characters) */ - name?: string; + name?: string | null; } /** @@ -69,7 +69,11 @@ export interface APITextBasedChannel extends APIChannelBa rate_limit_per_user?: number; } -export interface APIGuildChannel extends APIChannelBase { +export interface APIGuildChannel extends Omit, 'name'> { + /** + * The name of the channel (1-100 characters) + */ + name: string; /** * The id of the guild (may be missing for some channel objects received over gateway guild dispatches) */ @@ -101,7 +105,7 @@ export interface APIGuildChannel extends APIChannelBase; export interface APIGuildTextChannel - extends APITextBasedChannel, + extends Omit, 'name'>, APIGuildChannel { /** * Default duration for newly created threads, in minutes, to automatically archive the thread after recent activity @@ -141,7 +145,7 @@ export interface APIVoiceChannelBase extends APIGuildChan export interface APIGuildVoiceChannel extends APIVoiceChannelBase, - APITextBasedChannel { + Omit, 'name'> { /** * The camera video quality mode of the voice channel, `1` when not present * @@ -161,9 +165,18 @@ export interface APIDMChannelBase extends Omit; +export interface APIDMChannel extends Omit, 'name'> { + /** + * The name of the channel (always null for DM channels) + */ + name: null; +} export interface APIGroupDMChannel extends Omit, 'name'> { + /** + * The name of the channel (1-100 characters) + */ + name: string | null; /** * Application id of the group DM creator if it is bot-created */ @@ -172,10 +185,6 @@ export interface APIGroupDMChannel extends Omit extends APIChannelBa rate_limit_per_user?: number; } -export interface APIGuildChannel extends APIChannelBase { +export interface APIGuildChannel extends Omit, 'name'> { + /** + * The name of the channel (1-100 characters) + */ + name: string; /** * The id of the guild (may be missing for some channel objects received over gateway guild dispatches) */ @@ -101,7 +105,7 @@ export interface APIGuildChannel extends APIChannelBase; export interface APIGuildTextChannel - extends APITextBasedChannel, + extends Omit, 'name'>, APIGuildChannel { /** * Default duration for newly created threads, in minutes, to automatically archive the thread after recent activity @@ -141,7 +145,7 @@ export interface APIVoiceChannelBase extends APIGuildChan export interface APIGuildVoiceChannel extends APIVoiceChannelBase, - APITextBasedChannel { + Omit, 'name'> { /** * The camera video quality mode of the voice channel, `1` when not present * @@ -161,9 +165,18 @@ export interface APIDMChannelBase extends Omit; +export interface APIDMChannel extends Omit, 'name'> { + /** + * The name of the channel (always null for DM channels) + */ + name: null; +} export interface APIGroupDMChannel extends Omit, 'name'> { + /** + * The name of the channel (1-100 characters) + */ + name: string | null; /** * Application id of the group DM creator if it is bot-created */ @@ -172,10 +185,6 @@ export interface APIGroupDMChannel extends Omit extends APIChannelBa rate_limit_per_user?: number; } -export interface APIGuildChannel extends APIChannelBase { +export interface APIGuildChannel extends Omit, 'name'> { + /** + * The name of the channel (1-100 characters) + */ + name: string; /** * The id of the guild (may be missing for some channel objects received over gateway guild dispatches) */ @@ -101,7 +105,7 @@ export interface APIGuildChannel extends APIChannelBase; export interface APIGuildTextChannel - extends APITextBasedChannel, + extends Omit, 'name'>, APIGuildChannel { /** * Default duration for newly created threads, in minutes, to automatically archive the thread after recent activity @@ -141,7 +145,7 @@ export interface APIVoiceChannelBase extends APIGuildChan export interface APIGuildVoiceChannel extends APIVoiceChannelBase, - APITextBasedChannel { + Omit, 'name'> { /** * The camera video quality mode of the voice channel, `1` when not present * @@ -161,9 +165,18 @@ export interface APIDMChannelBase extends Omit; +export interface APIDMChannel extends Omit, 'name'> { + /** + * The name of the channel (always null for DM channels) + */ + name: null; +} export interface APIGroupDMChannel extends Omit, 'name'> { + /** + * The name of the channel (1-100 characters) + */ + name: string | null; /** * Application id of the group DM creator if it is bot-created */ @@ -172,10 +185,6 @@ export interface APIGroupDMChannel extends Omit extends APIChannelBa rate_limit_per_user?: number; } -export interface APIGuildChannel extends APIChannelBase { +export interface APIGuildChannel extends Omit, 'name'> { + /** + * The name of the channel (1-100 characters) + */ + name: string; /** * The id of the guild (may be missing for some channel objects received over gateway guild dispatches) */ @@ -101,7 +105,7 @@ export interface APIGuildChannel extends APIChannelBase; export interface APIGuildTextChannel - extends APITextBasedChannel, + extends Omit, 'name'>, APIGuildChannel { /** * Default duration for newly created threads, in minutes, to automatically archive the thread after recent activity @@ -141,7 +145,7 @@ export interface APIVoiceChannelBase extends APIGuildChan export interface APIGuildVoiceChannel extends APIVoiceChannelBase, - APITextBasedChannel { + Omit, 'name'> { /** * The camera video quality mode of the voice channel, `1` when not present * @@ -161,9 +165,18 @@ export interface APIDMChannelBase extends Omit; +export interface APIDMChannel extends Omit, 'name'> { + /** + * The name of the channel (always null for DM channels) + */ + name: null; +} export interface APIGroupDMChannel extends Omit, 'name'> { + /** + * The name of the channel (1-100 characters) + */ + name: string | null; /** * Application id of the group DM creator if it is bot-created */ @@ -172,10 +185,6 @@ export interface APIGroupDMChannel extends Omit; + +// Test channel names are properly typed +// Always non-null present for non-DM channels, always null for DM channel +expectType(partialChannel.name); +expectType(groupDMChannel.name); +expectType(dmChannel.name); +expectType(guildChannel.name);