Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to enable support of optional chaining operators in WebStorm

I work on a project where we use optional chaining operator (aka Elvis operator):

const baz = new obj?.foo?.bar?.baz()

Is it a way to make WebStorm understand it?

P.S. It's a part of stage-1 proposals: https://github.com/tc39/proposal-optional-chaining

like image 901
Sergei Panfilov Avatar asked Aug 24 '17 13:08

Sergei Panfilov


People also ask

How do I enable optional chaining?

To enable optional chaining, you need to install a package. At the time of writing, optional chaining is not natively supported in Javascript, it is a new feature introduced in ES2020. Until it is fully adopted we can get all the optional goodness by installing a package!

Does TypeScript support optional chaining?

Hence, since version 3.7, TypeScript has introduced optional chaining and nullish coalescing.

What version of node has optional chaining?

Node. js version 14 has included Optional Chaining (?.) operator as part of the updates/hightlights, which enable JavaScript developers to read the value of a property located deep within a chain of connected objects without having to check that each reference in the chain is valid.

Can I use it optional chaining?

You can use optional chaining when attempting to call a method which may not exist. This can be helpful, for example, when using an API in which a method might be unavailable, either due to the age of the implementation or because of a feature which isn't available on the user's device.


2 Answers

Finally typescript version 3.7 supports optional chaining. For webstorm to support it you need to update it to the latest version. It would work as expected.

Typescript - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html

Webstorm Release notes - https://blog.jetbrains.com/webstorm/2019/10/webstorm-2019-2-4/

like image 143
Archit Garg Avatar answered Sep 19 '22 16:09

Archit Garg


Here is an issue about this https://youtrack.jetbrains.com/issue/WEB-27592. Seems like it's resolved so we can wait for the feature in next build.

like image 28
Evgeniy Viniychuk Avatar answered Sep 18 '22 16:09

Evgeniy Viniychuk