如何在项目中使用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

本文详细介绍了如何在项目中引入并配置TypeScript,包括安装TypeScript包、设置tsconfig.json文件、安装类型定义依赖以及使用tsc命令将TypeScript转换为JavaScript。
6006

被折叠的 条评论
为什么被折叠?



