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”
导出分配不能与其他导出元素一起在模块中使用。
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 { }
}