Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda