I am seeing a a red underline when I'm using an optional chain, but the code runs fine as I am on node 14
Here's my setup:
node 14.1.0 eslint "^6.8.0"
.eslintrc.js
module.exports = { "env": { "node": true }, "extends": [ "eslint:recommended", ], "parserOptions": { "sourceType": "module", "ecmaVersion": 2020 }, "rules": { }, }
Support for optional chaining was added in ESLint 7.5. 0. Also, @typescript-eslint/prefer-optional-chain can be used in JavaScript projects.
Optional chaining is a safe and concise way to perform access checks for nested object properties. The optional chaining operator ?. takes the reference to its left and checks if it is undefined or null.
Go to C:\Users\\{YourWindowsUsername}\AppData\Local\Microsoft\TypeScript\ESLint . Open the package. json file. You should see the version of ESLint that is installed, in my case it is "eslint": "4.19.
You no longer need @babel/eslint-parser
as eslint@^7.5
now supports optional chanining.
Run the following to update eslint within your project:
npm install --save-dev eslint@^7.5
yarn add -D eslint@^7.5
And then, ensure your config is as follows:
{ "parserOptions": { "ecmaVersion": 2020 } }
module.exports = { "parserOptions": { "ecmaVersion": 2020 } }
See https://eslint.org/blog/2020/07/eslint-v7.5.0-released#optional-chaining-support for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With