typescript - 获取 tslint 错误:`解析错误:预期表达式`
问题描述
有人可以帮我解释一下吗?
我正在接受Failed to compile. Parsing error: Expression expected
这条线 -
isLogViewVisible: dashboard?.logView !== null
isLogViewVisible
在哪里boolean
interface IDashboard {
logView: ILogView
}
interface ILogView {
history: string
}
let dashboard: IDashboard | null
let logView: ILogView | null
const someVariable = {
isLogViewVisible: dashboard?.logView !== null
}
解决方案
:
用于类型信息,=
用于赋值(和===
相等):
isLogViewVisible = state.dashboard?.logView === null
或者如果你想让类型显式(在这里没用,它很容易推断):
const isLogViewVisible: boolean = state.dashboard?.logView === null
推荐阅读
- reactjs - 反应 useEffect 钩子无限循环
- reactjs - 一个数组的一个输出和嵌套在其中的数组的不同输出
- python - 在 docker 容器中运行时进程突然堆积内存
- angular - 角反应形式材料日期选择器手动输入格式DD/MM/YYYY
- javascript - 打字时如何使表格中所有单元格的生长高度相同?
- c++ - OpenGL - Reading cursor position correctly but cant draw line from it
- docker - 如何在 Docker 环境的根目录 (/) 中创建挂载配置
- c# - 使用 ArrayList 将代码从 VB.NET 转换为 C#
- python - spyder.ini 中是否有调整内存最大值的选项?
- npm - socket.io 设置没有同站点属性的跨站点 cookie