Skip to main content

TypeScript Setup

Vite​

New app with typescript support​

  • Use react-ts template
npm init vite
# use react-ts template
cd project-name
npm run dev

Add TypeScript to existing vite react app​

  • Add dependencies
npm install -D typescript @types/react @types/react-dom @types/jest
  • Rename existing js/jsx files to ts/tsx

    • Example: index.jsx → index.tsx
  • Run app with npm run dev


Create React App​

New react app with typescript support​

  • Use create-react-app template
npx create-react-app my-app --template typescript

Add TypeScript to existing react app​

  • Add dependencies
npm install -D typescript @types/node @types/react @types/react-dom @types/jest
  • Rename existing js/jsx files to ts/tsx

    • Example: index.jsx → index.tsx
  • Run app with npm run start