You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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 asetType
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 aUserContextMenuInteraction
or aMessageContextMenuInteraction
based on what type ofContextMenuCommandBuilder
it is. Without any such type information onContextMenuCommandBuilder
s, this is impossible.Ideal solution or implementation
I suggest that the
ContextMenuCommandBuilder
'ssetType
method return a narrower builder type to specify whichtype
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)
returnsContextMenuCommandBuilder & {type: T}
, whereT extends ContextMenuCommandType
. Another could be that it returns aContextMenuCommandBuilder<T>
, andT
would be used as the value of thetype
property to begin with, extending and defaulting toContextMenuCommandType
.Alternative solutions or implementations
No response
Other context
No response
The text was updated successfully, but these errors were encountered: