• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

126
Vistas
Tsx luxon type of DateTime

I have dates in luxon format, when I try to print information from the console it tells me this:

enter image description here

I get the following error TS2339: Property 'c' does not exist on type 'DateTime'.:

enter image description here

This is because I stated that last day elements are of type DateTime.

Does luxon have its own format that I can import?

Or is there a way to create a datatime type for luxon, so you don't get the error.

Can you give me a hand?

Code:

  const lNow = DateTime.now();
  const lThreeMonthsAgo = lNow.minus({month: 3}).startOf("week");
  let num = Math.ceil(lNow.diff(lThreeMonthsAgo, "days").days);
  let lastDays = [...Array(num).keys()].reduce(
      (acc, val) => [...acc, lThreeMonthsAgo.plus({day: val})],
      [] as Array<DateTime>
  );

  const month = lastDays.reduce((acc, val) => [...acc, val.c.month], [] as Array<number>);
  const unique_month = [...new Set(month)];
about 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I don't have any experience with luxon, but the typings show that year, month, etc. are declared as accessors, so you can just index directly them on a DateTime object, i.e. replace val.c.month with val.month.

TypeScript playground

about 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda