How can I define the property eventList
in the class ImplTestClass
to be an array with all possible values of AllowedEvents
, while extending the class TextClass
that accepts T
?
I'm stuck on this one. If anyone can provide guidance on how to achieve this, I would greatly appreciate it!
type EventMap = Record<string, unknown>;
abstract class TestClass<T extends EventMap> {
public eventList: Array<T[keyof T]>;
constructor() {
this.eventList = [];
}
}
interface AllowedEvents extends EventMap {
created: { time: string; userId: number; createdId: number; },
removed: { time: string; userId: number; removedId: number; }
}
class ImplTestClass extends TestClass<AllowedEvents> {
getEventList() {
return this.eventList;
// I would like `eventList` to have the type
// ({ time: string; userId: number; createdId: number; } | { time: string; userId: number; removedId: number; })[]
}
};