TypeScript + React


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

  1. Create a simple Next.js Project.
yarn create next-app <app-name>
  1. Install typescript, @types/node & @types/react as a dev dependency.
yarn add typescript @types/node @types/react -D
  1. Rename the files to .tsx (files with jsx) and .ts (files without jsx)

Renaming Screenshot

  1. Run yarn dev. Next.js will automatically detect TypeScript and generate a tsconfig.json file.

  2. (Optional). Restart your typescript server inside vscode by ctrl + shift + P and then TypeScript: Restart TS Server.

Screenshot from 2021-12-23 18-36-29