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 tots/tsx
- Example:
index.jsx
→index.tsx
- Example:
Run app with
npm run dev
Create React App
- Source: create-react-app docs
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 tots/tsx
- Example:
index.jsx
→index.tsx
- Example:
Run app with
npm run start