Optional chaining does not work with typescript parser
See original GitHub issuePrettier 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:
- Created 4 years ago
- Reactions:4
- Comments:9 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Still having the issue, I’m using prettier-vscode-4.4.0
Update : In my case, I deleted node_modules content + package-lock.json and run npm i, and it worked
Can confirm that updating prettier to the latest works