小编Bri*_*nka的帖子

在尝试使用箭头函数返回三元运算符时,如何修复ES6 Eslint错误?

我明白() => {}不需要返回,但是如果它不存在则Eslint抱怨未使用的表达式.

export const isInInterval = (from, to, target) => {
  if (isNaN(Date.parse(to)) && isNaN(Date.parse(from)) === true) {
    return
  }
  const toUnixTimestamp = time => new Date(time).getTime()
  toUnixTimestamp(to) - target > toUnixTimestamp(from) ? true : false
}
Run Code Online (Sandbox Code Playgroud)

这是函数:它试图找出某个指定的date(to)减去指定的period(target)是否晚于from.如果是这样,它应该返回true而在相反的情况下应该返回false.我一直碰到eslint错误expected assignment to a function call and instead saw expression.

我尝试多次重写它,但在大多数迭代中我得到`箭头函数期望没有返回错误,例如:

return(toUnixTimestamp(to) - target> toUnixTimestamp(from))?真假

javascript ternary-operator ecmascript-6 eslint

3
推荐指数
1
解决办法
463
查看次数