I'm having difficulties adding TypeScript to an already existing create-react-app application. Previously I've always added it before starting the project, simply by create-react-app my-app --scripts-version=react-scripts-ts
, but that doesn't work now.
The only "solution" I found here is:
react-scripts-ts
tsconfig.json
, tsconfig.test.json
, tslint.json
from the temporary project src folder to your project's src
folder.package.json
, change all the references to react-scripts
to react-scripts-ts
in the scripts section.This just seems like a weird workaround, and not very efficient. Does anyone know if it's possible to add it in a better way than this?
Create react app is basically a node package that we can simply install. The interesting part about this is that you can use it with TypeScript very easily by leveraging the use of npm or yarn depending on what your package manager preference is.
As of react-scripts 2.10 you can add TypeScript to an existing project or when creating a new project.
existing project
yarn add typescript @types/node @types/react @types/react-dom @types/jest --dev
...then rename your .js
files to .tsx
new project
yarn create react-app my-app --template typescript
You can read more here.
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