Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
Can i extends Dayjs class?

I'm using Dayjs, typescript.

I want to use like this

export class CustomDate extends dayjs.Dayjs {
  format() {
  }
}

It returns 'TypeError: Class extends value undefined is not a constructor or null'.

When I searched this, the reason occured this problem is circular dependency, but I cannot understand it...

is it incorrect way?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I dug though the source for a bit, and I think this will work. However, since dayjs doesn't officially support sub-classing, I wouldn't recommend doing this.

(You might have to keep digging through the source code though: https://github.com/iamkun/dayjs/blob/4a7b7d07c885bb9338514c234dbb708e24e9863e/src/index.js)

/* Extracting the underlying Datejs class */
const Dayjs_proto = Object.getPrototypeOf(dayjs());
const Dayjs = Dayjs_proto.constructor;
Dayjs.prototype = Dayjs_proto;

class CustomDate extends Dayjs {
  constructor(date) {
    super({
      date: date,
      args: arguments,
    });
  }
  format() {
  }
}

const myCustomDateObject = new CustomDate(new Date());
console.log(myCustomDateObject);
<script src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.10.7/dayjs.min.js"></script>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!