typescript 依赖于node ,因此先要安装 node,然后再安装typescript.这里假设你会能搞定安装
ctrl+shift+p , 输入 language ,出现 Config Display language ,安装一下中文,菜单就会变成中文了.
在 File -> 将文件夹添加到工作区,你的 typescript 的文件
菜单 “调试”->添加配置 编辑 luanch.json
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Launch Program", "program": "${workspaceFolder}\\hello.js", "outFiles": [ "${workspaceFolder}/**/*.js" ] } ] }修改你要调试的js文件
build.bat
node "C:\Users\Administrator\AppData\Roaming\npm\node_modules\typescript\bin\tsc" %1可以用build.bat hello.ts 调试了。
源代码 hello.ts :
var 全局_运行在网页 = false; namespace hello{ export class mycls { private 名字:string=""; private 地址:string=""; 设置名字(value:string) { this.名字 = value; } 设置地址(value:string) { this.地址 = value; } 获得名字():string { return this.名字; } 获得地址():string { return this.地址; } } function 欢迎(person:string) { return "欢迎您, " + person+",来到中国。"; } function 测试() { let 用户名 = "bkdrong"; console.log(全局_运行在网页); if(全局_运行在网页) { document.body.innerHTML = 欢迎(用户名); } else { console.log("用户名="+欢迎(用户名)); } } export function 主函数() { var x = new mycls; x.设置名字('bkdrong'); x.设置地址('beijing'); console.log(x.获得名字()); console.log(x.获得地址()); 测试(); let x1 = 1; x1 = 100; var x2 = 2; x2 = 100; console.log(x1); console.log(x2); } } hello.主函数(); 没有用 hello world 之类的,了无新意,我们用一下中文标识符吧,母语看着就是爽!!!和C++ 很类似 private public 等let 和 var 都可以修改值,没有什么区别类中变量需要初始化,负责警告函数参数类型也要指定,否则警告可以使用命名空间什么的,比只使用函数强不少。动态执行javascript ,就可以动态更新网站而不用重启typescript 编译为 javascript 有点类似 C/C++ 编译成 汇编语言有的人说typescript 是javascript 是语法糖;其实有糖吃挺好。(汇编也叫机器语言助记符)别的真没什么说的了,面向对象语言都很好用 ;命名空间,类,方法相当强大的利器。
学习这些参考了很多博客,谢谢。