I have been trying to translate a JS function to TS, in which I use Luxon.
The problem is that when I try to access the c
property from now(), I get the following error Typescript: TS2339: Property 'c' does not exist on type 'DateTime'.
import { DateTime as Luxon } from 'luxon';
const getCurrentHour = (): number => {
const dTime = Luxon.now();
return dTime.c.hour;
}
console.log(typeof Luxon.now()); // I get "DateTime"
console.log(Luxon.now()); // I can see the "c" property
I know that JavaScript's DateTime interface does not have this c
property, but how do I manage to write this code with Luxon and TypeScript? I have installed @types/luxon and tried to find a type export there, but did not succeed.
I had the same problem.
try return dTime.hour
instead of return dTime.c.hour