本章主要验证ts的安装,和最基本的ts转译成js
webpack从0开始搭建react的ts开发环境(1)
demo https://github.com/757566833/webpack-guide
1.init
npx typescript --init
init typescript 新建一个tsconfig.json文件,这个是ts主要依赖的东西
2.新建test命令
package.json 中scripts新建test
{
"devDependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0",
"tslint": "^5.20.1",
"typescript": "^3.7.4",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10"
},
"dependencies": {
"koa": "^2.11.0",
"koa-router": "^7.4.0",
"koa-send": "^5.0.0"
},
"scripts": {
"test":"tsc"
}
}
tsc的意义请自行查询typescript相关文档
- 新建test.ts文件
// 文件结构
|-node_modules
|-package.json
|-test.ts
|-tsconfig.json
|-yarn.lock
// test内容
const arr = [1,2,3]
const arr2 = [...arr]
4.运行
npm run test
- 生成test.js
6.ts安装成功
网友评论