TypeScript 2.1·续1
var Derived = (function (_super) { __extends(Derived, _super); function Derived() { var _this = _super.call(this) || this; _this.x = 2; return _this; } return Derived;}(Base));
这在继承内置类如Error,Array,Map等的行为上有了破坏性的改变。请阅读extending built-ins breaking change documentation。
配置继承
通常一个项目有多个输出版本,比如ES5和ES2015,调试和生产或Commonjs和System。只有几个配置选项在这两个版本之间改变,并且维护多个tsconfig.json文件是麻烦的。
TypeScript 2.1支持使用extends来继承配置,其中:
-
extends在tsconfig.json是新的顶级属性(与compilerOptions、files、include和exclude一起)。
-
extends的值是包含继承自其它tsconfig.json路径的字符串。
-
首先加载基本文件中的配置,然后由继承配置文件重写。
-
如果遇到循环,我们报告错误。
-
继承配置文件中的files、include和exclude会重写基本配置文件中相应的值。
-
在配置文件中找到的所有相对路径将相对于它们来源的配置文件来解析。
示例
configs/base.json:
{ "compilerOptions": { "allowJs": true, "noImplicitAny": true, "strictNullChecks": true }}
configs/tests.json:
{ "compilerOptions": { "preserveConstEnums": true, "stripComments": false, "sourceMaps": true }, "exclude": [ "../tests/baselines", "../tests/scenarios" ], "include": [ "../tests/**/*.ts" ]}
tsconfig.json:
{ "extends": "./configs/base", "files": [ "main.ts", "supplemental.ts" ]}
tsconfig.nostrictnull.json:
{ "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false }}
新编译参数--alwaysStrict
使用--alwaysStrict调用编译器原因:1.在严格模式下解析的所有代码。2.在每一个生成文件上输出"use strict";指令;
模块会自动使用严格模式解析。对于非模块代码,建议使用该编译参数。
