question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Throwing Error on Optional Chaining (TS 3.7.2)

See original GitHub issue

Summary

Prettier VSCode plugin is failing on new TypeScript in version 3.7.2 syntax (specifically optional chaining). Prettier 1.19.1 was release on 11/8/2019 adding support https://github.com/prettier/prettier/issues/6469

Steps To Reproduce:

  1. Add optional chaining syntax x?.y to a TS file
  2. Attempt to auto-format the TS file
  3. Check the Output window of VSCode, and there will be an error of Expression expected pointing to the ?.
  4. Auto-format fails

Expected result

No error should be thrown, and auto-format should succeed

Actual result

See steps to reproduce

VS Code Version: 1.40.0

Prettier & Prettier Plugin Version: 1.19.1 and 2.3.0 respectively

OS and version: macOS 10.14.6

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:15
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
riesvriendcommented, Nov 15, 2019

VSCode is still on 3.6.x, you need to force it to use the locally installed typescript in node_modules (to 3.7.2), see https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-newer-typescript-versions

3reactions
ntottencommented, Nov 11, 2019

Version 3.0 is now released to the normal extension location.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - TypeScript 3.7
At its core, optional chaining lets us write code where TypeScript can immediately ... There's a specific set of functions that throw an...
Read more >
Typescript optional chaining error: Expression expected.ts(1109)
Try ⌘ + Shift + p and choosing Select TypeScript Version . If it's not 3.7+, that's the issue. The easiest fix is...
Read more >
Optional chaining (?.) - JavaScript - MDN Web Docs - Mozilla
If the object accessed or function called is undefined or null , it returns undefined instead of throwing an error. Try it.
Read more >
What is wrong with optional chaining and how to fix it - DEV ...
Optional chaining simplifies above and removes a lot of errors by saying that values considered as no value are only two - null...
Read more >
Optional chaining '?.' - The Modern JavaScript Tutorial
innerHTML property of null . And in some cases, when the absence of the element is normal, we'd like to avoid the error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found