diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 27fd856715c0..87c47c465dc3 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1162,10 +1162,10 @@ export class CommandInteractionOptionResolver( + public getChannel( name: string, required: true, - channelTypes?: T[], + channelTypes?: readonly T[], ): Extract< NonNullable['channel']>, { @@ -1177,10 +1177,10 @@ export class CommandInteractionOptionResolver; - public getChannel( + public getChannel( name: string, required?: boolean, - channelTypes?: T[], + channelTypes?: readonly T[], ): Extract< NonNullable['channel']>, { @@ -3713,9 +3713,11 @@ export class ApplicationCommandManager< id?: Snowflake, options?: FetchApplicationCommandOptions, ): Promise>; - public set(commands: ApplicationCommandDataResolvable[]): Promise>; public set( - commands: ApplicationCommandDataResolvable[], + commands: readonly ApplicationCommandDataResolvable[], + ): Promise>; + public set( + commands: readonly ApplicationCommandDataResolvable[], guildId: Snowflake, ): Promise>; private static transformCommand(command: ApplicationCommandDataResolvable): RESTPostAPIApplicationCommandsJSONBody; @@ -3748,21 +3750,21 @@ export class ApplicationCommandPermissionsManager< options: | (FetchSingleOptions & { token: string; - channels?: (GuildChannelResolvable | ChannelPermissionConstant)[]; - roles?: (RoleResolvable | RolePermissionConstant)[]; - users: UserResolvable[]; + channels?: readonly (GuildChannelResolvable | ChannelPermissionConstant)[]; + roles?: readonly (RoleResolvable | RolePermissionConstant)[]; + users: readonly UserResolvable[]; }) | (FetchSingleOptions & { token: string; - channels?: (GuildChannelResolvable | ChannelPermissionConstant)[]; - roles: (RoleResolvable | RolePermissionConstant)[]; - users?: UserResolvable[]; + channels?: readonly (GuildChannelResolvable | ChannelPermissionConstant)[]; + roles: readonly (RoleResolvable | RolePermissionConstant)[]; + users?: readonly UserResolvable[]; }) | (FetchSingleOptions & { token: string; - channels: (GuildChannelResolvable | ChannelPermissionConstant)[]; - roles?: (RoleResolvable | RolePermissionConstant)[]; - users?: UserResolvable[]; + channels: readonly (GuildChannelResolvable | ChannelPermissionConstant)[]; + roles?: readonly (RoleResolvable | RolePermissionConstant)[]; + users?: readonly UserResolvable[]; }), ): Promise; public set( @@ -4321,7 +4323,7 @@ export interface ChatInputApplicationCommandData extends BaseApplicationCommandD description: string; descriptionLocalizations?: LocalizationMap; type?: ApplicationCommandType.ChatInput; - options?: ApplicationCommandOptionData[]; + options?: readonly ApplicationCommandOptionData[]; } export type ApplicationCommandData = @@ -4331,13 +4333,13 @@ export type ApplicationCommandData = export interface ApplicationCommandChannelOptionData extends BaseApplicationCommandOptionsData { type: CommandOptionChannelResolvableType; - channelTypes?: ApplicationCommandOptionAllowedChannelTypes[]; - channel_types?: ApplicationCommandOptionAllowedChannelTypes[]; + channelTypes?: readonly ApplicationCommandOptionAllowedChannelTypes[]; + channel_types?: readonly ApplicationCommandOptionAllowedChannelTypes[]; } export interface ApplicationCommandChannelOption extends BaseApplicationCommandOptionsData { type: ApplicationCommandOptionType.Channel; - channelTypes?: ApplicationCommandOptionAllowedChannelTypes[]; + channelTypes?: readonly ApplicationCommandOptionAllowedChannelTypes[]; } export interface ApplicationCommandRoleOptionData extends BaseApplicationCommandOptionsData { @@ -4407,14 +4409,14 @@ export interface ApplicationCommandAutocompleteStringOptionData export interface ApplicationCommandChoicesData extends Omit { type: CommandOptionChoiceResolvableType; - choices?: ApplicationCommandOptionChoiceData[]; + choices?: readonly ApplicationCommandOptionChoiceData[]; autocomplete?: false; } export interface ApplicationCommandChoicesOption extends Omit { type: CommandOptionChoiceResolvableType; - choices?: ApplicationCommandOptionChoiceData[]; + choices?: readonly ApplicationCommandOptionChoiceData[]; autocomplete?: false; } @@ -4456,22 +4458,25 @@ export interface ApplicationCommandBooleanOption extends BaseApplicationCommandO export interface ApplicationCommandSubGroupData extends Omit { type: ApplicationCommandOptionType.SubcommandGroup; - options: ApplicationCommandSubCommandData[]; + options: readonly ApplicationCommandSubCommandData[]; } export interface ApplicationCommandSubGroup extends Omit { type: ApplicationCommandOptionType.SubcommandGroup; - options?: ApplicationCommandSubCommand[]; + options?: readonly ApplicationCommandSubCommand[]; } export interface ApplicationCommandSubCommandData extends Omit { type: ApplicationCommandOptionType.Subcommand; - options?: Exclude[]; + options?: readonly Exclude< + ApplicationCommandOptionData, + ApplicationCommandSubGroupData | ApplicationCommandSubCommandData + >[]; } export interface ApplicationCommandSubCommand extends Omit { type: ApplicationCommandOptionType.Subcommand; - options?: Exclude[]; + options?: readonly Exclude[]; } export interface ApplicationCommandNonOptionsData extends BaseApplicationCommandOptionsData { @@ -4527,11 +4532,11 @@ export interface ApplicationCommandPermissionsUpdateData { id: Snowflake; guildId: Snowflake; applicationId: Snowflake; - permissions: ApplicationCommandPermissions[]; + permissions: readonly ApplicationCommandPermissions[]; } export interface EditApplicationCommandPermissionsMixin { - permissions: ApplicationCommandPermissions[]; + permissions: readonly ApplicationCommandPermissions[]; token: string; } diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index cd8c8771a880..552d39986b47 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -163,6 +163,14 @@ import { ThreadManager, FetchedThreads, FetchedThreadsMore, + ApplicationCommandChannelOptionData, + ApplicationCommandChannelOption, + ApplicationCommandChoicesOption, + ApplicationCommandChoicesData, + ApplicationCommandSubGroup, + ApplicationCommandSubCommand, + ChatInputApplicationCommandData, + ApplicationCommandPermissionsManager, } from '.'; import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd'; import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders'; @@ -1355,7 +1363,7 @@ declare const applicationCommandManager: ApplicationCommandManager; applicationCommandManager.set([applicationCommandData]), ); expectType>>( - applicationCommandManager.set([applicationCommandData], '0'), + applicationCommandManager.set([applicationCommandData] as const, '0'), ); // Test inference of choice values. @@ -1377,6 +1385,41 @@ declare const applicationCommandManager: ApplicationCommandManager; } } +declare const applicationCommandPermissionsManager: ApplicationCommandPermissionsManager< + {}, + {}, + Guild | null, + Snowflake +>; +{ + applicationCommandPermissionsManager.add({ permissions: [], token: '' }); + applicationCommandPermissionsManager.add({ permissions: [] as const, token: '' }); + applicationCommandPermissionsManager.set({ permissions: [], token: '' }); + applicationCommandPermissionsManager.set({ permissions: [] as const, token: '' }); + applicationCommandPermissionsManager.remove({ channels: [], roles: [], users: [], token: '' }); + + applicationCommandPermissionsManager.remove({ + channels: [] as const, + roles: [] as const, + users: [] as const, + token: '', + }); +} + +declare const chatInputApplicationCommandData: ChatInputApplicationCommandData; +{ + chatInputApplicationCommandData.options = []; + chatInputApplicationCommandData.options = [] as const; +} + +declare const applicationCommandChannelOptionData: ApplicationCommandChannelOptionData; +declare const applicationCommandChannelOption: ApplicationCommandChannelOption; +{ + applicationCommandChannelOptionData.channelTypes = [] as const; + applicationCommandChannelOptionData.channel_types = [] as const; + applicationCommandChannelOption.channelTypes = [] as const; +} + declare const applicationNonChoiceOptionData: ApplicationCommandOptionData & { type: CommandOptionNonChoiceResolvableType; }; @@ -1387,10 +1430,32 @@ declare const applicationNonChoiceOptionData: ApplicationCommandOptionData & { applicationNonChoiceOptionData.choices; } +declare const applicationCommandChoicesData: ApplicationCommandChoicesData; +declare const applicationCommandChoicesOption: ApplicationCommandChoicesOption; +{ + applicationCommandChoicesData.choices = []; + applicationCommandChoicesData.choices = [] as const; + applicationCommandChoicesOption.choices = []; + applicationCommandChoicesOption.choices = [] as const; +} + +declare const applicationCommandSubCommandData: ApplicationCommandSubCommandData; +declare const applicationCommandSubCommand: ApplicationCommandSubCommand; +{ + applicationCommandSubCommandData.options = []; + applicationCommandSubCommandData.options = [] as const; + applicationCommandSubCommand.options = []; + applicationCommandSubCommand.options = [] as const; +} + declare const applicationSubGroupCommandData: ApplicationCommandSubGroupData; +declare const applicationCommandSubGroup: ApplicationCommandSubGroup; { expectType(applicationSubGroupCommandData.type); - expectType(applicationSubGroupCommandData.options); + applicationSubGroupCommandData.options = []; + applicationSubGroupCommandData.options = [] as const; + applicationCommandSubGroup.options = []; + applicationCommandSubGroup.options = [] as const; } declare const autoModerationRuleManager: AutoModerationRuleManager; @@ -1814,6 +1879,7 @@ client.on('interactionCreate', async interaction => { expectType( interaction.options.getChannel('test', true, [ChannelType.GuildForum, ChannelType.GuildVoice]), ); + expectType(interaction.options.getChannel('test', true, [ChannelType.GuildText] as const)); expectType( interaction.options.getChannel('test', false, [ChannelType.GuildForum, ChannelType.GuildVoice]), );