#Conditionnal type
1 messages · Page 1 of 1 (latest)
Can you give me an example?
i mean, an example would be pretty much the entire thing
export abstract class DiscordSlashCommand<DataType> {
/**
*
*/
readonly subcommands?:
| Collection<string, DiscordSlashCommand<ApplicationCommandOptionData>>
| undefined = undefined;
/**
*
*/
abstract readonly data: DataType extends ApplicationCommandData
? ApplicationCommandData
: ApplicationCommandOptionData;
I tried something like that but it's not exactly what I want
I'd like DataType to be optional for example
export abstract class DiscordSlashCommand<T extends Collection<string, DiscordSlashCommand<null>> | null = Collection<string, DiscordSlashCommand<null>> | null> {
abstract readonly subcommands: T
abstract readonly data: T ...
}
Well, that doesn't work since data should be either ApplicationCommandData or ApplicationCommandOptionData
you can specify that as a conditional after T
I'm also trying to understand this thing 🤔
or an interface would probably be better
wait no interface wouldn't work
!hb generics
btw ^
Can you elaborate please ? I’m trying to understand
T extends ... ? ... : ... kinda thing
but you'll need a few to handle all the appropriate cases
Thank you!
Looks like it's not working...
export abstract class DiscordSlashCommand<T extends Collection<string, DiscordSlashCommand<null>> | null = Collection<string, DiscordSlashCommand<null>> | null> {
/**
*
*/
abstract readonly subcommands?: T;
/**
*
*/
abstract readonly data: T extends Collection<string, DiscordSlashCommand>
? ApplicationCommandData
: ApplicationCommandOptionData;
Maybe I could just extend the class to create a DiscordSlashSubcommand and override the type?