如何在项目中使用typescript
安装typescript包
npm install -g typescript
npm install typescript
配置tsconfig.json
- 执行
tsc --init
- 修改tsconfig.json
json
> {
"compilerOptions": {
"target": "es6",
"allowJs": true,
"jsx": "react",
"outDir": "build",
"rootDir": "src",
"sourceMap": false,
"noImplicitAny": false
},
"filesGlob": [
"typings/**/*.d.ts",
"src/**/*.ts",
"src/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
安装type依赖
shell
npm install @type react
npm install @type react-native
根据项目安装需要的type