assertEventDerived.ts 687 B

1234567891011121314
  1. import Event from "@/modules/EventsModule/Event";
  2. // eslint-disable-next-line @typescript-eslint/ban-types
  3. export default (EventClass: Event) => {
  4. // Make sure the provided EventClass has Event as the parent somewhere as a parent. Not Event itself, as that constructor requires an additional constructor parameter
  5. // So any class that extends Event, or that extends another class that extends Event, will be allowed.
  6. let classPrototype = Object.getPrototypeOf(EventClass);
  7. while (classPrototype) {
  8. if (classPrototype === Event) break;
  9. classPrototype = Object.getPrototypeOf(classPrototype);
  10. }
  11. if (!classPrototype)
  12. throw new Error("Provided event class is not a event.");
  13. };