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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With