Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

71
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)];
7 months 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

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos