对于新建的react项目,可以使用下列的命令创建自带TypeScript配置的初始项目。
npx create-react-app my-app --template typescript # or yarn create react-app my-app --template typescript
对于已存在的通过create-react-app创建的项目,可以使用下列命令添加TypeScript依赖。
npm install --save typescript @types/node @types/react @types/react-dom @types/jest # or yarn add typescript @types/node @types/react @types/react-dom @types/jest