From 7322547172e2d34bd04ef131db277801fccf7f99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Rom=C3=A1n?= Date: Wed, 7 Jul 2021 18:34:39 +0200 Subject: [PATCH] types: fixed unreachable overloads (#6062) --- typings/index.d.ts | 23 ++++++---------- typings/index.ts | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 15 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 38a403bed..181f23ef1 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2071,19 +2071,15 @@ export class ApplicationCommandManager< null >; private commandPath({ id, guildId }: { id?: Snowflake; guildId?: Snowflake }): unknown; + public create(command: ApplicationCommandData): Promise; public create(command: ApplicationCommandData, guildId: Snowflake): Promise; - public create(command: ApplicationCommandData, guildId?: Snowflake): Promise; public delete(command: ApplicationCommandResolvable, guildId?: Snowflake): Promise; + public edit(command: ApplicationCommandResolvable, data: ApplicationCommandData): Promise; public edit( command: ApplicationCommandResolvable, data: ApplicationCommandData, guildId: Snowflake, ): Promise; - public edit( - command: ApplicationCommandResolvable, - data: ApplicationCommandData, - guildId?: Snowflake, - ): Promise; public fetch( id: Snowflake, options: FetchApplicationCommandOptions & { guildId: Snowflake }, @@ -2093,14 +2089,11 @@ export class ApplicationCommandManager< id?: Snowflake, options?: FetchApplicationCommandOptions, ): Promise>; + public set(commands: ApplicationCommandData[]): Promise>; public set( commands: ApplicationCommandData[], - guildId?: Snowflake, + guildId: Snowflake, ): Promise>; - public set( - commands: ApplicationCommandData[], - guildId?: Snowflake, - ): Promise>; private static transformCommand(command: ApplicationCommandData): unknown; } @@ -2163,7 +2156,7 @@ export class GuildApplicationCommandManager extends ApplicationCommandManager; public edit(command: ApplicationCommandResolvable, data: ApplicationCommandData): Promise; public fetch(id: Snowflake, options?: BaseFetchOptions): Promise; - public fetch(id?: Snowflake, options?: BaseFetchOptions): Promise>; + public fetch(id?: undefined, options?: BaseFetchOptions): Promise>; public set(commands: ApplicationCommandData[]): Promise>; } @@ -2190,7 +2183,7 @@ export class GuildChannelManager extends CachedManager< options?: BaseFetchOptions, ): Promise; public fetch( - id?: Snowflake, + id?: undefined, options?: BaseFetchOptions, ): Promise< Collection @@ -2206,7 +2199,7 @@ export class GuildEmojiManager extends BaseGuildEmojiManager { options?: GuildEmojiCreateOptions, ): Promise; public fetch(id: Snowflake, options?: BaseFetchOptions): Promise; - public fetch(id?: Snowflake, options?: BaseFetchOptions): Promise>; + public fetch(id?: undefined, options?: BaseFetchOptions): Promise>; } export class GuildEmojiRoleManager extends DataManager { @@ -2356,7 +2349,7 @@ export class RoleManager extends CachedManager public readonly premiumSubscriberRole: Role | null; public botRoleFor(user: UserResolvable): Role | null; public fetch(id: Snowflake, options?: BaseFetchOptions): Promise; - public fetch(id?: Snowflake, options?: BaseFetchOptions): Promise>; + public fetch(id?: undefined, options?: BaseFetchOptions): Promise>; public create(options?: CreateRoleOptions): Promise; public edit(role: RoleResolvable, options: RoleData, reason?: string): Promise; } diff --git a/typings/index.ts b/typings/index.ts index d03f898f3..fdfba0c60 100644 --- a/typings/index.ts +++ b/typings/index.ts @@ -1,9 +1,19 @@ import { + ApplicationCommand, + ApplicationCommandData, + ApplicationCommandManager, + ApplicationCommandResolvable, + CategoryChannel, Client, Collection, Constants, DMChannel, + GuildApplicationCommandManager, + GuildChannelManager, + GuildEmoji, + GuildEmojiManager, GuildMember, + GuildResolvable, Intents, Message, MessageActionRow, @@ -17,13 +27,19 @@ import { PartialTextBasedChannelFields, Permissions, ReactionCollector, + Role, + RoleManager, Serialized, ShardClientUtil, ShardingManager, + Snowflake, + StageChannel, + StoreChannel, TextBasedChannelFields, TextChannel, ThreadChannel, User, + VoiceChannel, } from '..'; const client: Client = new Client({ @@ -512,3 +528,56 @@ assertType<'close'>(Constants.ShardEvents.CLOSE); assertType<1>(Constants.Status.CONNECTING); assertType<0>(Constants.Opcodes.DISPATCH); assertType<2>(Constants.ClientApplicationAssetTypes.BIG); + +declare const applicationCommandData: ApplicationCommandData; +declare const applicationCommandResolvable: ApplicationCommandResolvable; +declare const applicationCommandManager: ApplicationCommandManager; +{ + type ApplicationCommandType = ApplicationCommand<{ guild: GuildResolvable }>; + + assertType>(applicationCommandManager.create(applicationCommandData)); + assertType>(applicationCommandManager.create(applicationCommandData, '0')); + assertType>( + applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData), + ); + assertType>( + applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData, '0'), + ); + assertType>>( + applicationCommandManager.set([applicationCommandData]), + ); + assertType>>( + applicationCommandManager.set([applicationCommandData], '0'), + ); +} + +declare const guildApplicationCommandManager: GuildApplicationCommandManager; +assertType>>(guildApplicationCommandManager.fetch()); +assertType>>(guildApplicationCommandManager.fetch(undefined, {})); +assertType>(guildApplicationCommandManager.fetch('0')); + +declare const guildChannelManager: GuildChannelManager; +{ + type AnyChannel = TextChannel | VoiceChannel | CategoryChannel | NewsChannel | StoreChannel | StageChannel; + + assertType>(guildChannelManager.create('name', { type: 'voice' })); + assertType>(guildChannelManager.create('name', { type: 'category' })); + assertType>(guildChannelManager.create('name', { type: 'text' })); + assertType>(guildChannelManager.create('name', { type: 'news' })); + assertType>(guildChannelManager.create('name', { type: 'store' })); + assertType>(guildChannelManager.create('name', { type: 'stage' })); + + assertType>>(guildChannelManager.fetch()); + assertType>>(guildChannelManager.fetch(undefined, {})); + assertType>(guildChannelManager.fetch('0')); +} + +declare const roleManager: RoleManager; +assertType>>(roleManager.fetch()); +assertType>>(roleManager.fetch(undefined, {})); +assertType>(roleManager.fetch('0')); + +declare const guildEmojiManager: GuildEmojiManager; +assertType>>(guildEmojiManager.fetch()); +assertType>>(guildEmojiManager.fetch(undefined, {})); +assertType>(guildEmojiManager.fetch('0'));