React + TypeScript Setup and Usage Guide
React + TypeScript Setup and Usage Guide 1. Create React App with TypeScript npx create-react-app react-ts-app --template typescript cd react-ts-app npm start This sets up a React project with TypeScript ready out of the box. tsconfig.json will be auto-generated. The default source files will be .tsx instead of .js . 2. Manual Setup (if starting with JavaScript project and adding TS) If you started with a plain React app and want to add TypeScript later: npm install --save typescript @types/node @types/react @types/react-dom @types/jest Rename .js and .jsx files in src/ to .ts and .tsx respectively. Run npm start , and CRA will generate tsconfig.json automatically. React Scripts version 2.1.1+ supports this smooth TS integration. 3. Typical package.json scripts "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", ...
Comments
Post a Comment