算术运算的左侧和右侧必须为"any","number"或枚举类型 [英] The left -hand and right hand side of an arithmetic operation must be of type 'any', 'number' or an enum type

查看:5306
本文介绍了算术运算的左侧和右侧必须为"any","number"或枚举类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误.我无法找出我到底出了什么问题.有人可以帮我解决问题的方法

I am getting the following error. I am not able to find out where exactly i went wrong.Can someone help me out with the solution

代码

 function() {
    this.devices.forEach(device => {
      let lastConnect = device.lastConnection.split('+');
      lastConnect = lastConnect[0] + 'Z';
      let diff = Math.abs(new Date() - new Date(lastConnect));//getting error here
}

推荐答案

我发现了问题所在.

您编写的代码仅在 JavaScript

Math.abs(new Date() - new Date(lastConnect)) .

为了使其能够在 Typescript 中使用,请更新代码,如下所示:

In order to make it work in Typescript, update the code as shown below:

Math.abs(Date().getTime() - new Date(lastConnect).getTime());

这篇关于算术运算的左侧和右侧必须为"any","number"或枚举类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆