Getting tslint error: `Parsing error: Expression expected`
11,689
:
is for type information, use =
for assignment (and ===
for equality):
isLogViewVisible = state.dashboard?.logView === null
or if you want to make the type explicit (useless here, it is trivially inferred):
const isLogViewVisible: boolean = state.dashboard?.logView === null
Related videos on Youtube
Author by
Ting Ting Chan
Updated on June 04, 2022Comments
-
Ting Ting Chan almost 2 years
Can someone shed me some light on this?
I’m getting
Failed to compile. Parsing error: Expression expected
with this line -isLogViewVisible: dashboard?.logView !== null
whereisLogViewVisible
isboolean
interface IDashboard { logView: ILogView } interface ILogView { history: string } let dashboard: IDashboard | null let logView: ILogView | null const someVariable = { isLogViewVisible: dashboard?.logView !== null }
-
jhanschoo about 4 yearsMy suspicion is that your TSLint is relying on a TypeScript version that doesn't yet support optional chaining. Optional chaining is a feature that was introduced in TypeScript 3.7 , i.e. relatively recently in terms of stable company codebases. Note that TSLint's TS may not be the TS in your project, depending on your IDE setup. If this doesn't help you resolve your question, I encourage you to pose some information on your IDE setup to help users answer your question.
-
-
Ting Ting Chan about 4 yearsThanks for your reply! Really appreciated it. I am sorry I didn't make myself clear. Let me try to rephrase the question.
-
Ting Ting Chan about 4 yearsand when I hover logView on that line, it shows types "ILogView | null | undefined"
-
Ting Ting Chan about 4 yearsI got it. it's
state.dashboard !== null && state.dashboard.logView !== null
. Thanks!