简体   繁体   English

在angular1项目中为$ injector.get重载打字稿接口定义

[英]Overloading typescript interface definition for $injector.get in angular1 project

I am working on migrating an angular1 project from javascript to typescript, and would like to add to the overloaded $injector.get method to include the project's own injectable types. 我正在将angular1项目从javascript迁移到打字稿,并希望添加到重载的$ injector.get方法中以包括项目自己的可注入类型。 I read this typescript doc on merging interfaces. 我阅读了有关合并接口的此打字稿文档 I added this into an imported d.ts file: 我将其添加到导入的d.ts文件中:

import TrendDisplayService from 'services/TrendDisplayService';
declare namespace angular {
  export module ng.auto {
      export interface IInjectorService {
        get(name: 'trendDisplayService'): TrendDisplayService
      }
  }

}

However I am still seeing the "not assignable" type error when doing the following: 但是,在执行以下操作时,我仍然看到“无法分配”的类型错误:

let trend:TrendDisplayService = $injector.get('trendDisplayService');

Any thoughts? 有什么想法吗?

In the declaration module should be auto and not ng.auto. 在声明模块中,应该是auto而不是ng.auto。

declare namespace angular {
    export module auto {
        export interface IInjectorService {
            get(name: 'trendDisplayService'): TrendDisplayService
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM