Manipulating dates in Typescript

Rmag Breaking News

The correct way to subtract or add dates when using Typescript

const diff = new Date().valueOf() date.valueOf();

valueOf gives you the date as number which satisfies Typescript.

Doing the following produces a warning

const diff = new Date() date;
// Error: The left-hand side of an arithmetic operation must be of type ‘any’, ‘number’, ‘bigint’ or an enum type.ts(2362)

Leave a Reply

Your email address will not be published. Required fields are marked *