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
Share:
11,689

Related videos on Youtube

Ting Ting Chan
Author by

Ting Ting Chan

Updated on June 04, 2022

Comments

  • Ting Ting Chan
    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 where isLogViewVisible is boolean

    interface IDashboard {
      logView: ILogView
    }
    
    interface ILogView {
      history: string
    }
    
    let dashboard: IDashboard | null
    let logView: ILogView | null
    
    
    const someVariable = {
      isLogViewVisible: dashboard?.logView !== null
    }
    
    • jhanschoo
      jhanschoo about 4 years
      My 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
    Ting Ting Chan about 4 years
    Thanks 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
    Ting Ting Chan about 4 years
    and when I hover logView on that line, it shows types "ILogView | null | undefined"
  • Ting Ting Chan
    Ting Ting Chan about 4 years
    I got it. it's state.dashboard !== null && state.dashboard.logView !== null. Thanks!