Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 打字稿-难度“;扩展;不规则静电_Angularjs_Typescript - Fatal编程技术网

Angularjs 打字稿-难度“;扩展;不规则静电

Angularjs 打字稿-难度“;扩展;不规则静电,angularjs,typescript,Angularjs,Typescript,不久前,我问了一个类似的问题,得到了很多帮助,但即使有了答案,我仍在与这段代码作斗争 我已经在typescript中编写了一个与googleapi(gapi)一起使用的小型服务和一个与之配套的界面,在我的代码中列出了这一点 gapiService.ts 现在,我可以这样使用它们,但是出于OCD的目的,我想将它们附加到angular名称空间/模块,作为ng加载的一部分。所以我可以叫他们 ng.GoogleAuthenticationService ng.IGoogleAuthenticationS

不久前,我问了一个类似的问题,得到了很多帮助,但即使有了答案,我仍在与这段代码作斗争

我已经在
typescript
中编写了一个与
googleapi
(gapi)一起使用的小型服务和一个与之配套的界面,在我的代码中列出了这一点

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

ng.GoogleAuthenticationService
ng.IGoogleAuthenticationService
我原以为这会奏效,但我不断得到的错误,它要么找不到它们,要么其他一些错误。我已经浏览了以下错误列表

  • 类型“IAngularStatic”上不存在属性“GoogleAuthenticationService”
  • 模块“angular”没有导出的成员“IGoogleAuthenticationService”
  • 导出分配不能与其他导出元素一起在模块中使用。
你知道如何实现我的目标吗?我快疯了

gapiAuth.d.ts ng.GoogleAuthenticationService ng.IGoogleAuthenticationService

只需将它们包装在
angular
名称空间中:

namespace angular {
  class GoogleAuthenticationService implements IGoogleAuthenticationService {
     // ...
  }

  interface IGoogleAuthenticationService extends ng.IServiceProvider { }
}

我想用
module{}
围绕整个代码(类加接口)会出现在这里,我想你或多或少会问同样的问题。方括号中的声明是什么?这是trippy-我不知道这些是什么意思。不,用
模块角度
包围它是不起作用的。我得到了一个重复的标识符。这不起作用。它使所有其他angular实例都出错。我假设,因为它更改了
angular
的定义。将它们放在名为
foo.d.ts
的新文件中。我怀疑您正在粘贴一个现有文件,该文件已经是一个无法工作的模块。它只是说有一个重复的标识符。
declare module 'angular' {
    interface IGoogleAuthenticationService{}
    var GoogleAuthenticationService: GoogleAuthenticationService
}
namespace angular {
  class GoogleAuthenticationService implements IGoogleAuthenticationService {
     // ...
  }

  interface IGoogleAuthenticationService extends ng.IServiceProvider { }
}