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
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!
Hence, since version 3.7, TypeScript has introduced optional chaining and nullish coalescing.
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.
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.
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/
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.
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