Create a class that extends javascript Date does not work

45 views Asked by At

I am trying to create a class Birthdate extending Date in typescript :

class Birthday extends Date {
  public isYoungerThen(other: Date): boolean {
    return this.getTime() > other.getTime();
  }

  get isAdult(): boolean {
    const past = new Date();
    past.setFullYear(past.getFullYear() - 18)
    return this.getTime() <= past.getTime();
  }
}

But when trying to call : new Birthday('2022-08-08T16:04:25+02:00').isAdult this fails with an error : TypeError: this is not a Date object.

Can you help me figuring out what I could have done wrong ?

Thx

0

There are 0 answers