Creating a React app with TypeScript
Now, we will create a React app using Vite, and we will use TypeScript instead of JavaScript. We will use TypeScript later when we develop the frontend for our car backend. As we mentioned earlier, Vite comes with built-in TypeScript support:
- Create a new React app using the following command:
npm create vite@latest
- Next, name your project
tsapp
, and select the React framework and the TypeScript variant:
Figure 9.7: React TypeScript app
- Then, move to your app folder, install dependencies, and run your app using the following commands:
cd tsapp npm install npm run dev
- Open your app folder in VS Code, and you will see that the filename of our
App
component isApp.tsx
:Figure 9.8: App.tsx
The file extension of TypeScript React files is
.tsx
(combining JSX with TypeScript). The regular file extension of TypeScript files is.ts
.
- Locate the
tsconfig...