安装Typescript:html
使用npm安装:前端
查看版本:node
选择可手的IDE:typescript
Typescript的编写,在Visual Studio和Webstrorm上都能获得较好的代码支持,这里推荐两篇博文,让你们能够方便地进行配置:npm
Visual Studio Code:http://www.cnblogs.com/sunjie9606/p/5945540.htmljson
Webstorm:http://blog.chinaunix.net/uid-30198739-id-5739410.html浏览器
官网在线Compiler:http://www.typescriptlang.org/play/index.htmlui
Typescript编译配置-tsconfig.jsones5
1 { 2 "compilerOptions": { 3 "module": "commonjs", 4 "target": "es5", //编译以后生成的JavaScript文件须要遵循的标准。有三个候选项:es三、es五、es2015。 5 "noImplicitAny": false, //为false时,若是编译器没法根据变量的使用来判断类型时,将用any类型代替。为true时,将进行强类型检查,没法推断类型时,提示错误。 6 "sourceMap": true, //编译时是否生成对应的source map文件。这个文件主要用于前端调试。当前端js文件被压缩引用后,出错时可借助同名的source map文件查找源文件中错误位置。 7 "allowJs": true 8 } 9 , 10 "exclude": [ 11 "node_modules" 12 ] 13 }
Typescript "HelloWorld"spa
greeter.ts
greeter.js
running result:
tsconfig中target不一样的属性值的效果
Before Compilation(TS):
After Compilation(JS):
ES3:
ES5:
ES6: