Create-react-app: Unsupported `as const` TypeScript syntax

Created on 30 Mar 2019  路  3Comments  路  Source: facebook/create-react-app

Is this a bug report?

Yes.

Typescript 3.4 introduces as const syntax. However, using create-react-app with --typescript doesn't support this syntax yet, because it uses an older version of @babel/preset-typescript that doesn't support as const. PR https://github.com/facebook/create-react-app/commit/3c9c21a2858a3397cceca51b3a299878b29c5c7b updates this dependency, amongst others, which fixes this issue but it hasn't been released yet.

Steps to Reproduce

  1. npx create-react-app my-app etc.
  2. add some variable to app.tsx that uses as const
  3. App crashes: unexpected token

Screenshot 2019-03-30 at 19 35 14

Alternatively, following the same steps directly from the create-react-app source code doesn't result in the app crashing.

question typescript

Most helpful comment

The PR you referenced is included as part of the 3.0 alpha release. If you want to try it out see #6475. Otherwise it will be part of the 3.0 official release.

All 3 comments

The PR you referenced is included as part of the 3.0 alpha release. If you want to try it out see #6475. Otherwise it will be part of the 3.0 official release.

Thanks for the clarification!

The same is true for readonly on array return types in case anyone else finds this issue looking for that.
I tried upgrading to the CRA3 release and upgrading TypeScript in the solution and it worked.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dualcnhq picture dualcnhq  路  3Comments

wereHamster picture wereHamster  路  3Comments

JimmyLv picture JimmyLv  路  3Comments

adrice727 picture adrice727  路  3Comments

xgqfrms-GitHub picture xgqfrms-GitHub  路  3Comments