開始TypeScript開發之前,我們得掌握如何創建一個最初的工程。
下面是創建一個新的工程需要用到的若干語句。
https://www.jianshu.com/p/0e37a793ac3a
https://www.cnblogs.com/xiaoxiaochengxuyuan/p/6137574.html
typescript開發的准備工作:
1.准備工作
1.1安裝node.js (www.nodejs.cn)
1.2.安裝 typescript
npm install -g typescript
npm i -g typescript
npm i -g nodemon
npm install typings --global
2.typescript里面找不到 'http'模塊
npm install -s http
npm install -s @types/http
npm install --save @types/core-js
npm install --save-dev @types/node
npm install –save @types/jquery
===============================
3.開始建立typescript的工程
3.1.初始tsc環境,生成tsconfig.json文件
tsc --init
3.2.初始化 npm環境,生成package.json文件
npm init -y
3.3.vs打開當前目錄
code .
3.4.寫完ts文件之后,記得build(構建)一下
3.5.打開watch功能
[Terminal]-->[Run Task],選擇 watch
win10 腳本被禁用問題:
set-ExecutionPolicy RemoteSigned
在power shell輸入這個命令。
參考地址:https://blog.csdn.net/wqnmlgbsz/article/details/100654258
功能拓展:
1.添加代碼檢查插件
npm install --save-dev eslint
npm install --save-dev typescript @typescript-eslint/parser
npm install --save-dev @typescript-eslint/eslint-plugin
參考地址: https://ts.xcatliu.com/engineering/lint
或者,直接在vscode的工具欄側面,搜索 ESLint 插件,安裝即可。