【发布时间】:2015-09-22 07:32:44
【问题描述】:
自从升级到 TypeScript 1.6 后,我的所有 ng.Types 似乎都出现了虚假错误:
Typescript 1.6 类“派生类”不能扩展类“基类”: 类型基类和派生类的属性 $timeout 类型是 不兼容
这是代码示例:
module app.Test {
class derivedClass extends baseClass {
// Notice there's nothing in the derived class
}
class baseClass {
constructor(timeout: ng.ITimeoutService, val1: string, otherVal: ng.ILogService) {
var vm = this;
vm.$timeout = timeout;
vm.someValue = val1;
vm.otherValue = otherVal;
}
$timeout: ng.ITimeoutService; // angular.ITimeoutService works
someValue: string;
otherValue: ng.ILogService;
}
}
angular.ITimeoutService 有效,或添加 import ng= angular;在我的模块中也可以。这在以前的 Typescript 版本中不是问题。
最好的做法是在使用之前在每个模块中重复别名(例如:import ng = angular),即使这已经在 angular.d.ts 中完成?
【问题讨论】:
-
这是通过新项目还是在现有项目上对 TypeScript 进行就地升级? (可能是 angular.d.ts 的较新版本导致问题,而不是 v1.6)
-
对现有项目进行就地升级。不幸的是,我还升级了 angular.d.ts 文件
标签: angularjs typescript