type Repliable = CommandInteraction | AnySelectMenuInteraction | ButtonInteraction | ModalSubmitInteraction | MessageComponentInteraction
export class ComponentManager<Itype extends Repliable> {
constructor(public interaction: Itype) {}
public getData(): Itype extends AnySelectMenuInteraction ? Itype["values"] : Itype extends ButtonInteraction ? Itype["customId"] : null {
if (this.interaction.isAnySelectMenu()) return this.interaction.values
if (this.interaction.isButton()) return this.interaction.customId
if (this.interaction.isChatInputCommand()) return null
}
}
The end goal I am looking for with this code is to narrow the return type of getData function based on the generic type passed into it. However I keep running into Type 'string[]' is not assignable to type 'Itype extends AnySelectMenuInteraction ? Itype["values"] : Itype extends ButtonInteraction<CacheType> ? Itype["customId"] : null'.ts(2322) for all of my returns despire them being inside a guard.
How can I force my getData function to know its return type is a string[] when its initialized with an AnySelectMenuInteraction, and a string when it is initialized with a ButtonInteraction and so forth.
Thanks in advance,