Introduction to TypeScript
official statement
Features
-
Compatible with ES specifications, but also has its own specifications (such as namespace)
-
Language as a Service (IDE, method declarations for 3rd party libraries, etc.)
static analysis
input error
non-empty judgment
access permission
Extensibility
TS适合大规模JS应用,正如他的官方宣传语JavaScript that scales
。
- 类型系统+静态分析+智能感知/提示,使大规模的应用代码质量更高,更好维护。
- 有类似VSCode这样配套的IDE支持,方便的查看引用关系,并进行重构,再也不用全局搜索,一个个修改了。
- 数据结构(应用配置、前后端接口等JSON格式数据)的类型校验,和强类型的后端配合更为无缝、健壮,方便后期前后端整体迭代、重构。
超集
对于历史包袱比较多的老项目,不建议完全替换Babel,但是可以曲线引入TS,用TS编译到ES6,再用Babel来编译到ES5。
代码运行时质量
和Babel、Flow的对比
- TypeScript 是推荐套餐,Babel 系列是自助餐。
- TypeScript自带编译器,包含ES最新规范,还有自己的Features和类型校验;Flow是一个类型校验工具。在类型校验这块两者目前已经相差不大。
- Babel and Flow are promoted by Facebook, TypeScript is promoted by Microsoft, and they have a good ecosystem, but I personally feel that Flow is not mature enough at present (I heard that FB recently recruited some Lisp experts to do this, but I have not verified it), TS comes from a big bull (author of C# and Delphi). The current ecological development is very good, and the community reputation is also very good. It feels more reliable (not to say that Flow is unreliable).