Getting Started
Creating a React project using TypeScript
Run the following command to create a TypeScript React Project.
yarn create react-app <app-name> --template-typescript
Migrating a Next project from JS to TS
- Create a simple
Next.js
Project.
yarn create next-app <app-name>
- Install
typescript
,@types/node
&@types/react
as a dev dependency.
yarn add typescript @types/node @types/react -D
- Rename the files to
.tsx
(files with jsx) and.ts
(files without jsx)
-
Run
yarn dev
. Next.js will automatically detect TypeScript and generate atsconfig.json
file. -
(Optional). Restart your typescript server inside vscode by
ctrl + shift + P
and thenTypeScript: Restart TS Server
.