Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Means of distinguishing different ContextMenuCommandBuilder types #8765

Closed
GrantGryczan opened this issue Oct 17, 2022 · 1 comment
Closed

Comments

@GrantGryczan
Copy link

GrantGryczan commented Oct 17, 2022

Which package is the feature request for?

builders

Feature

I'm trying to develop a TypeScript library that adds more abstractions around common Discord.js patterns and boilerplates, but I've run into a problem when trying to do this for context menu commands, because TypeScript has access to no information about what type of context menu a ContextMenuCommandBuilder represents. This is despite that it has a setType method, which I believe should narrow the type to provide that information. I need my types to be able to know whether the resulting interaction will be a UserContextMenuInteraction or a MessageContextMenuInteraction based on what type of ContextMenuCommandBuilder it is. Without any such type information on ContextMenuCommandBuilders, this is impossible.

Ideal solution or implementation

I suggest that the ContextMenuCommandBuilder's setType method return a narrower builder type to specify which type the builder is. I don't care how it's done, as long as it is convenient to distinguish using TypeScript.

One example could be that .setType(type: T) returns ContextMenuCommandBuilder & {type: T}, where T extends ContextMenuCommandType. Another could be that it returns a ContextMenuCommandBuilder<T>, and T would be used as the value of the type property to begin with, extending and defaulting to ContextMenuCommandType.

Alternative solutions or implementations

No response

Other context

No response

@didinele
Copy link
Member

didinele commented Oct 1, 2024

Resolved with #10448 (merged soon)

@didinele didinele closed this as completed Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants