From 29fd89f23c22ac5b4ce0a3ed34f5d27e28b1a0b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=86MB=C3=98?= <69138346+TAEMBO@users.noreply.github.com> Date: Wed, 15 May 2024 10:36:02 -0700 Subject: [PATCH] fix(SlashCommandBuilder): add missing shared properties (#10255) * types(SlashCommandBuilder): add missing shared properties * Add tests for types * Fix formatting * Enable Vitest type checking --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- packages/builders/__tests__/types.test.ts | 17 +++++++++++++++++ .../slashCommands/mixins/SharedSlashCommand.ts | 11 +++++++++++ vitest.config.ts | 4 ++++ 3 files changed, 32 insertions(+) create mode 100644 packages/builders/__tests__/types.test.ts diff --git a/packages/builders/__tests__/types.test.ts b/packages/builders/__tests__/types.test.ts new file mode 100644 index 000000000000..dfd6abef35f8 --- /dev/null +++ b/packages/builders/__tests__/types.test.ts @@ -0,0 +1,17 @@ +import { expectTypeOf } from 'vitest'; +import { SlashCommandBuilder, SlashCommandStringOption, SlashCommandSubcommandBuilder } from '../src/index.js'; + +const getBuilder = () => new SlashCommandBuilder(); +const getStringOption = () => new SlashCommandStringOption().setName('owo').setDescription('Testing 123'); +const getSubcommand = () => new SlashCommandSubcommandBuilder().setName('owo').setDescription('Testing 123'); + +type BuilderPropsOnly = Pick< + Type, + keyof { + [Key in keyof Type as Type[Key] extends (...args: any) => any ? never : Key]: any; + } +>; + +expectTypeOf(getBuilder().addStringOption(getStringOption())).toMatchTypeOf(); + +expectTypeOf(getBuilder().addSubcommand(getSubcommand())).toMatchTypeOf(); diff --git a/packages/builders/src/interactions/slashCommands/mixins/SharedSlashCommand.ts b/packages/builders/src/interactions/slashCommands/mixins/SharedSlashCommand.ts index 4d321073c79c..9e178f82f1f1 100644 --- a/packages/builders/src/interactions/slashCommands/mixins/SharedSlashCommand.ts +++ b/packages/builders/src/interactions/slashCommands/mixins/SharedSlashCommand.ts @@ -27,6 +27,17 @@ export class SharedSlashCommand { public readonly options: ToAPIApplicationCommandOptions[] = []; + /** + * @deprecated Use {@link SharedSlashCommand.setDefaultMemberPermissions} or {@link SharedSlashCommand.setDMPermission} instead. + */ + public readonly default_permission: boolean | undefined = undefined; + + public readonly default_member_permissions: Permissions | null | undefined = undefined; + + public readonly dm_permission: boolean | undefined = undefined; + + public readonly nsfw: boolean | undefined = undefined; + /** * Sets whether the command is enabled by default when the application is added to a guild. * diff --git a/vitest.config.ts b/vitest.config.ts index c6e4f62c4e29..60e469dda8f4 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -4,6 +4,10 @@ export default defineConfig({ test: { exclude: ['**/node_modules', '**/dist', '.idea', '.git', '.cache'], passWithNoTests: true, + typecheck: { + enabled: true, + include: ["**/__tests__/types.test.ts"] + }, coverage: { enabled: true, all: true,