🏠 back to Observable

Javascript Optional Chaining Unsupported by Code Formatting

Javascript optional chaining is working in Observable runtime. like:

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/) and it’s now supported. I think maybe it’s time to update the auto formatting logic?

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.

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)


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