flppv
flppv

Reputation: 4299

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

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?

Upvotes: 24

Views: 26589

Answers (2)

Ben Clayton
Ben Clayton

Reputation: 82267

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.

Upvotes: 22

flppv
flppv

Reputation: 4299

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.

Upvotes: 17

Related Questions