Search code examples
javascriptvisual-studio-codejshintoptional-chaining

JSHint suppress error for optional chaining


I was writing some Javascript when I found out about optional chaining (?.). I decided that I would need it in some code I was writing. When I finished typing out the code, I noticed that JSHint was giving me an error that stated Expected an identifier and instead saw '.'. (E030) jshint(E030). The following code runs without any error (MDN compatibility table), but JSHint still gives a warning for it.

var x = {
  y: {
    z: 123
  }
};

console.log(x.y?.z)

I have found another StackOverflow question relating to this, but the question specifically asks about ESLint, while this question is about JSHint. I also searched the issues tab of the JSHint GitHub repository, but I couldn't find anything. Is there any way to suppress this kind of error? I am using Visual Studio Code Insiders.

The editor information taken from Code - Insiders > About Visual Studio Code - Insiders:

Version: 1.48.0-insider
Commit: d13d2fc56da7a2f8bcad4256212db0661fcbba45
Date: 2020-08-05T05:26:44.946Z (20 hrs ago)
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 19.5.0

Solution

  • Add: "esversion": 11 to your jshint file. Optional chaining was added in version 11.