# Javascript Optional Chaining Unsupported by Code Formatting

**URL:** <https://talk.observablehq.com/t/javascript-optional-chaining-unsupported-by-code-formatting/4758>\
**Category:** Feedback\
**Created:** [March 11, 2021, 1:38am UTC](https://talk.observablehq.com/t/javascript-optional-chaining-unsupported-by-code-formatting/4758 "2021-03-11T01:38:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vorbei](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/vorbei/32/1000_2.png) [@vorbei](https://talk.observablehq.com/u/vorbei)\
**Post date:** [March 11, 2021, 1:38am UTC](https://talk.observablehq.com/t/javascript-optional-chaining-unsupported-by-code-formatting/4758/1 "2021-03-11T01:38:57Z")

</div>

Javascript optional chaining is working in Observable runtime. like:  
foo?.bar?.property

But the auto code formatting (a.k.a. Prettier in current build of Observable, including the ‘Next’ Observable) is not supported. When there is “?.” in codes, it will fail and console will output errors.

I’ve tried the latest online version of Prettier ([https://prettier.io/](https://prettier.io/)) and it’s now supported. I think maybe it’s time to update the auto formatting logic?

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [March 13, 2021, 11:00pm UTC](https://talk.observablehq.com/t/javascript-optional-chaining-unsupported-by-code-formatting/4758/2 "2021-03-13T23:00:04Z")

</div>

Note that even with optional chaining you still need to declare `foo`. Prettier itself does not trigger any errors, as it merely formats your code.

If you’re still encountering this problem, please provide more details, like the error message that you’re seeing, or ideally a notebook link to demonstrate the error.

---

<div class="post-metadata">

**Author:** ![vorbei](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/vorbei/32/1000_2.png) [@vorbei](https://talk.observablehq.com/u/vorbei)\
**Post date:** [March 16, 2021, 8:33am UTC](https://talk.observablehq.com/t/javascript-optional-chaining-unsupported-by-code-formatting/4758/3 "2021-03-16T08:33:38Z")

</div>

As in the following picture and notebook, it’s not working for the current Prettier setup of Observable.  
The result is fine and chaining is working on runtime.

[Optional Chaining / Zhida Cheng / Observable (observablehq.com)](https://observablehq.com/@vorbei/optional-chaining?ui=classic)

 ![optional_chaining](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/f/f6eb75f0239b3f13853c0e1ad5f84b642641e1a3.jpeg)

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [March 16, 2021, 9:40am UTC](https://talk.observablehq.com/t/javascript-optional-chaining-unsupported-by-code-formatting/4758/4 "2021-03-16T09:40:56Z")

</div>

Thanks for the added details and example! I’ve created a bug report:

> <https://github.com/observablehq/feedback/issues/49>
>
> Describe the bug
> The version of Prettier that is used by Observable cannot handle the optional chaining operator.
> To Reproduce
> Steps to reproduce the...
