Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript 3.7.2 - Support for the experimental syntax 'optionalChaining' isn't currently enabled

Tags:

In my project I am using TS 3.7.2 which should support optional chaining. But when I try to use it like that: const state = urlParams.state?.toString() I get the error:

Support for the experimental syntax 'optionalChaining' isn't currently enabled

Add @babel/plugin-proposal-optional-chaining (https://git.io/vb4Sk) to the 'plugins' section of your Babel config to enable transformation.

I checked release notes and didn't see any requirements about adding tsconfig options for that feature.

I am wondering if I need babel plugin & config when I am using TS already, and how should I fix the error?

like image 923
flppv Avatar asked Nov 25 '19 22:11

flppv


2 Answers

This sounds like you are using an older version of create-react-app.

Versions earlier than v3.3 don't support optionalChaining in the babel config it uses.

Support was added in CRA v3.3. See other answers for how to upgrade.

like image 191
Ben Clayton Avatar answered Sep 22 '22 18:09

Ben Clayton


Solved with a release of the CRA v3.3.0. If someone still has same error as in the title make sure you've upgraded react-scripts package.

like image 25
flppv Avatar answered Sep 19 '22 18:09

flppv