discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.44k stars 3.97k forks source link

Typing issues for ContextMenuCommandBuilder#setType() method #10535

Closed virtual-designer closed 1 month ago

virtual-designer commented 1 month ago

Which package is this bug report for?

builders

Issue description

It seems like in the latest version, the parameter type of the ContextMenuCommandBuilder#setType() method has been changed, which is now causing type errors when passing ApplicationCommandType.Message or ApplicationCommandType.User. Passing literal values like 2 or 3 works, though.

The issue seems to be a bit weird, there are two ApplicationCommandTypes defined, because the package @discordjs/builders apparently has its own discord-api-types installation which I found out by looking into the node_modules directory. So the project's discord-api-types and @discordjs/builders's version of discord-api-types.

It should be noted that the main project had only two dependencies: discord.js@14.16.4 and typescript. The discord-api-types that's right inside the node_modules directory of the project is what I'm referring to as "project's own discord-api-types. And the other discord-api-types was at node_modules/@discordjs/builders/node_modules/discord-api-types.

I also noticed the versions of both discord-api-types package were different, which is why the package manager probably installed two versions of discord-api-types.

So in short, in both packages the definitions for ApplicationCommandType are the same, however, TypeScript kind of behaves like a nominal type system when using enums, so it doesn't seem to like multiple discord-api-types at once. The solution would probably be to upgrade the version of discord-api-types in @discordjs/builders so that the package manager doesn't need to install multiple versions.

Please correct me if any of the things I've said are wrong.

Code sample

import { ApplicationCommandType, ContextMenuCommandBuilder } from "discord.js";

new ContextMenuCommandBuilder()
    .setType(ApplicationCommandType.Message);
/*           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   */
/*           This line causes a type error.   */

Versions

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

Not applicable

Which gateway intents are you subscribing to?

Not applicable

I have tested this issue on a development release

No response

didinele commented 1 month ago

Sort of duplicate of #10533, already resolved, wait for the next release.

virtual-designer commented 1 month ago

Sort of duplicate of #10533, already resolved, wait for the next release.

Ah, my bad, I didn't look into the previously closed issues. Nevermind.