"extending" IAngularStatic 的难度



不久前我问了一个类似的问题,得到了很多帮助,但即使有了答案,我也很难理解这段代码。

我已经用typescript编写了一个与google apigap)一起使用的小型服务,以及一个与之配套的接口,在我的代码中如下所示;

gapService.ts

class GoogleAuthenticationService implements IGoogleAuthenticationService {
   // ...
}
interface IGoogleAuthenticationService extends ng.IServiceProvider { }

现在,我可以这样使用它们,但出于OCD的目的,我想将它们附加到angular名称空间/模块,作为ng加载的一部分。所以我可以叫他们。。。

ng.GoogleAuthenticationService
ng.IGoogleAuthenticationService

我以为这会起作用,但我一直收到错误,要么找不到它们,要么是其他错误。我已经查看了以下错误列表。。。

  • Property 'GoogleAuthenticationService' does not exist on type 'IAngularStatic'
  • Module 'angular' has no exported member 'IGoogleAuthenticationService'
  • An export assignment cannot be used in a module with other exported elements.

知道如何实现我的目标吗?它把我逼疯了。

gapAuth.d.ts

declare module 'angular' {
    interface IGoogleAuthenticationService{}
    var GoogleAuthenticationService: GoogleAuthenticationService
}

ng.谷歌身份验证服务ng.IGoogleAuthenticationService

只需将它们封装在angular命名空间:中

namespace angular {
  class GoogleAuthenticationService implements IGoogleAuthenticationService {
     // ...
  }
  interface IGoogleAuthenticationService extends ng.IServiceProvider { }
}

最新更新