I have found out the issue.
The code you have written works only in Javascript
Math.abs(new Date() - new Date(lastConnect)) .
In order to make it work in Typescript, update the code as shown below:
Math.abs(new Date().getTime() - new Date(lastConnect).getTime());