一.环境安装
1.安装Node.Js环境
2.使用 npm包管理,安装TypeScript
npm install -g typescript
更新到最新版本:
npm update -g typescript
3.查看当前TypeScript的版本
tsc -v
三、在VS Code中对于 v1.14以后的版本,编辑器只需要配置 tsconfig.json文件就可以了
注:VsCode v.1.14对tasks.json进行了调整,详细 参考 :https://code.visualstudio.com/docs/editor/tasks#vscode
1.配置tsconfig.json,和一起前一样,见介绍2
注:watch可以 配置监视当执行保存时及时编译文件。
{
"compilerOptions": {
"target": "es5",
"noImplicitAny": true,
"module": "commonjs",
"removeComments": true,
"sourceMap": false,
"watch": true,
"outDir": "out/"
},
"include":[
"src/*"
],
"exclude": [
"js"
]
}
2.自动生成task.json、
点击任务》配置生成默认任务,选择tsc就可以了
或者使用Ctrl+Shift+P
结果如下:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "lint",
"problemMatcher": [
"$eslint-stylish"
],
"presentation": {
"reveal": "never"
},
},
{
"taskName": "Run tests",
"type": "shell",
"command": "./scripts/test.sh",
"windows": {
"command": ".\\scripts\\test.cmd"
},
"group": "test",
"presentation": {
"reveal": "always",
"panel": "new"
}
}
]
}
二.在VS Code工具下创建、编译项目(这针对于VsCodev1.14以前的版本)
1.使用VS Code打开执行文件夹作为工作目录
2.创建tsconfig.json文件,配置*.ts的编译输出等,更多参考:https://www.tslang.cn/docs/handbook/tsconfig-json.html
{
"compilerOptions": {
"target": "es5",
"noImplicitAny": false,
"module": "commonjs",
"removeComments": true,
"sourceMap": false,
"outDir": "Golang/TypeScript/"
}
//"include":[
// "ts"
// ],
//"exclude": [
// "js"
// ]
}
文件名tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for thedocumentation about the tasks.json format
"version": "2.0.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "always",
"problemMatcher": "$tsc"
}
编译成功会将在指定的输出目录生成 *.ts => *.js
如下图:
更多:
TypeScript 简介整理
NodeJs开发环境搭建之Visual Studio Code
Apache Cordova开发环境搭建(二)VS Code