我遇到了错误
error TS4025: Exported variable 'UserApiClientModule' has or is using private name 'UserApiClient'.
在下面的代码中:
export var UserApiClientModule = {
fromConfiguration: (configuration: Configuration) => {
@NgModule({
providers: [
{
provide: BASE_PATH,
useValue: basePath
},
{
provide: Configuration,
useValue: configuration
},
RegistrationApi,
AuthApi,
AccountApi,
ContactsApi,
ContactOrgsApi
],
imports: [
CommonModule,
HttpModule
]
})
class UserApiClient { }
return UserApiClient;
}
}
我怀疑解决方案是以某种方式导出 UserApiClient 类型,但我不确定该怎么做,因为它是在函数中声明的。
最佳答案
这里的重点是:
Typescript tries to guess what is the returned type of all the public parts. And not only guess, but to really declare the
UserApiClient
as a part of returned type of thefromConfiguration
call
而且因为我们返回的东西不是导出的,而是内部的.. 有问题。但是我们可以很容易地返回其他东西,例如一些通用的界面……或者至少是神奇的any
// change this
export var UserApiClientModule = {
fromConfiguration: (configuration: Configuration) => {
@NgModule({
...
// to that
export var UserApiClientModule = { // below is the change
fromConfiguration: (configuration: Configuration) : any => {
@NgModule({
...
我宁愿声明一些通用接口(interface) IHaveDynamicData
... 实际上与这里显示的类似情况一样 How can I use/create dynamic template to compile dynamic Component with Angular 2.0?
关于angular - 导出返回类 : Exported variable has or is using private name 的函数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40034979/