Adding TypeScript to existing create-react-app app
advice wanted: simple react typescript setup
what are the best practices for a react typescript project
First React app made with Typescript
What’s the fastest correct way to create a React + TypeScript app?
Can I mix JavaScript and TypeScript in the same React project?
Should I start a new React project with TypeScript, or add it later?
Videos
I tried "create-react-app" with the typescript template but so far, I really dislike it. The react-scripts part is unclear and confusing to me.
What is your go to for setting up a react project?
I think I will try one of the following two steps next:
a) use nextjs (did a small website using RNW and with it, was an easy to use setup)
b) set up react without any helper scripts
All I need:
react app (spa is enough)
typescript
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 in the docs.
If you are having trouble, the following from the troubleshooting section of the docs might help:
Troubleshooting
If your project is not created with TypeScript enabled, npx may be using a cached version of create-react-app. Remove previously installed versions with npm uninstall -g create-react-app or yarn global remove create-react-app (see #6119).
If you want to add TypeScript to the existing react app use below command
npm install --save-dev typescript @types/node @types/react @types/react-dom @types/jest
Rename at least one file from js/jsx to .ts/tsx. For example, rename index.js to index.ts or index.tsx and then start the server. This will generate the tsconfig.json file automatically and you are ready to write React in TypeScript.