Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make VSCode maintain proper syntax highlighting for .JS files after using Elvis (?) operator?

In my .js files, when I use an elvis operator const something = data?.info?.set , the entire file turns red after the line used.

How can I make VSCode recognize elvis operators and maintain syntax proper highlighting?

Note: I use metro-react-native-babel-preset and eslint, which by default allows for optionals in pure .js files (not typescript)

I have installed https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-next and also followed the instructions to enable it. However, my code is still pure red color starting the line after I use the ? operator.

like image 914
TIMEX Avatar asked Dec 10 '19 21:12

TIMEX


People also ask

Does VS Code have syntax highlighting?

Syntax highlighting determines the color and style of source code displayed in the Visual Studio Code editor. It is responsible for colorizing keywords like if or for in JavaScript differently than strings and comments and variable names.

How do I set VS Code to default settings?

The easiest way to reset VS Code back to the default settings is to clear your user settings.json file. You can open the settings.json file with the Preferences: Open Settings (JSON) command in the Command Palette (Ctrl+Shift+P).


1 Answers

VS Code 1.41 supports syntax highlighting and IntelliSense for optional chaining (?.) out of the box.

If you still see red highlighting with VS Code 1.41, either:

  • One of your installed extensions is causing this. ESlint for example
  • You are using an older typescript version in your workspace. Make sure to use TS 3.7+
like image 120
Matt Bierner Avatar answered Oct 31 '22 15:10

Matt Bierner