Discord now has three distinct types of application commands: chat input (slash commands), message (right click message context menu), and user (right click user context menu). These 3 different types are part of an enum: ApplicationCommandType. My goal is to implement a class where I can say new Command<T>(CommandProperties<T>) where T is one of the 3 types, and what happens inside the class depends on which type T is. I also have several interfaces giving the possible constructor arguments for each type. So far what I have looks like this:
export class Command<T extends ApplicationCommandType> {
constructor(properties: CommandProperties<T>) {
}
}
export type CommandProperties<T extends ApplicationCommandType> =
T extends ApplicationCommandType.ChatInput
? SlashCommandProperties
: T extends ApplicationCommandType.Message
? MessageContextMenuCommandProperties
: UserContextMenuCommandProperties;
CommandProperties takes a command type and finds the right properties (arguments) for that type. So far, this works for creating new Commands from the outside with arguments that correspond to the command type T.
However I don't know how (or if it's possible) to change how the Command class works (assigning properties, different methods, etc) depending on T. Possibly what I'm looking for is a way to "overload" the class differentiated by type parameter as opposed to arguments(?)
The final goal is a class and types that work such that I can use new Command<T>(CommandProperties<T>) to create a new command of one of the 3 types that functions uniquely as that specific type.
if anyones got ideas, it'd be much appreciated, thanks:3