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.

Optional chaining does not work with typescript parser

See original GitHub issue

Prettier 1.19.1 Playground link

# Options (if any):
--parser=typescript

Input:

value.optional?.length;

Output:

SyntaxError: Expression expected. (1:16)
> 1 | value.optional?.length;
    |                ^
  2 | 

Expected behavior: The code is parsed without error.

When I switch to --parser=babel, it works, the problem is only with typescript parser

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
cothmancommented, Apr 23, 2020

Still having the issue, I’m using prettier-vscode-4.4.0

SyntaxError: Expression expected. (123:29)
  121 |   if (!stateShowUserInfoModal) return <>{modifiedChildren}</>;
  122 | 
> 123 |   if (!userNetworks && data?.networks?.getUserNetworks) {

Update : In my case, I deleted node_modules content + package-lock.json and run npm i, and it worked

2reactions
Spaxecommented, Mar 2, 2020

Can confirm that updating prettier to the latest works

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support Optional Chaining in Typescript Parser #1035
This breaks Prettier auto-formatting too, if that is done via eslint. 2
Read more >
With TypeScript enabled, optional chaining is flagged as ...
With TypeScript enabled, optional chaining is flagged as error in .js files. What steps will reproduce the problem? ... No error is expected...
Read more >
Typescript Optional Chaining Not Recognized
When I try to use the new `?.` syntax though it is marked as an error. It looks like the editor thinks it...
Read more >
Module Parse Failed With Optional-Chaining in Angular 10 ...
Using Optional-Chaining in Angular 10 while targeting es2020 will result in the error 'Module parse failed: Unexpected token'.
Read more >
no-unsafe-optional-chaining
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
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