So I really don't know if this is possible but I wanted to ask anyway. So I have a class named Row
export class Row {
buttons: MenuOption[] | ButtonOption[];
rowType: RowTypes;
constructor(buttons: MenuOption[] | ButtonOption[], rowType: RowTypes) {
this.buttons = buttons;
this.rowType = rowType;
}
}
And it has a property called rowType which is basically an enum
export enum RowTypes {
SelectMenu = 0,
ButtonMenu = 1
}
It also has a property called buttons and It can be either a MenuOption array, or a ButtonOption array. Now here's the problem. Can I tell typescript to change the type of the property buttons based on the rowType value? So for example if the rowType value is 1 then the buttons type is MenuOption.