【发布时间】:2021-01-15 16:26:47
【问题描述】:
场景:
我的项目正在使用最新版本的@okta/okta-angular。它导出类“OktaAuthService”。我想使用模块扩充来添加一个方法
我尝试过的
import { OktaAuthService } from '@okta/okta-angular';
declare module '@okta/okta-angular' {
interface OktaAuthService {
getUserRole(): Promise<RoleEnum>;
}
}
OktaAuthService.prototype.getUserRole = function (): Promise<Role> {
return OktaAuthService.prototype.getUser().then(userClaims => {
//pseudo code
if user has claim
return Role;
//
});
}
根据https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation,这应该可以,但是
-
界面似乎是导入的重影(TS2693 'OktaAuthService' 仅指一种类型,但在此处用作值(我在其中设置了 getUserRole 函数)
-
如果我删除了新函数,但离开了模块,那么在我从“@okta/okta-angular”导入的所有地方编译都会失败
我在这里误会了什么?
【问题讨论】:
标签: angular typescript okta module-augmentation