首页 > 解决方案 > 获取 tslint 错误:`解析错误:预期表达式`

问题描述

有人可以帮我解释一下吗?

我正在接受Failed to compile. Parsing error: Expression expected这条线 -

isLogViewVisible: dashboard?.logView !== nullisLogViewVisible在哪里boolean

interface IDashboard {
  logView: ILogView
}

interface ILogView {
  history: string
}

let dashboard: IDashboard | null
let logView: ILogView | null


const someVariable = {
  isLogViewVisible: dashboard?.logView !== null
}

标签: typescript

解决方案


:用于类型信息,=用于赋值(和===相等):

isLogViewVisible = state.dashboard?.logView === null

或者如果你想让类型显式(在这里没用,它很容易推断):

const isLogViewVisible: boolean = state.dashboard?.logView === null

推荐阅读