【问题标题】:How to deal with spurious type script error: types of property $timeout of types base class and derived class are incompatible?如何处理虚假类型脚本错误:类型基类和派生类的属性类型 $timeout 不兼容?
【发布时间】: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


【解决方案1】:

最好的做法是在使用之前在每个模块中重复别名(例如:import ng = angular),即使这已经在 angular.d.ts 中完成

没有。发生错误可能是因为您已经这样做了。

您发布的代码默认运行良好:

【讨论】:

  • 不,没有别名会发生错误。这段代码以前是这样工作的,直到我升级到 Typescript 1.6 和最新的 angular.d.ts 文件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-27
  • 2012-09-08
  • 2021-09-26
  • 2018-07-31
  • 1970-01-01
  • 1970-01-01
  • 2011-06-04
相关资源
最近更新 更多