Question Scenario:
In my current project, I am utilizing the latest version of @okta/okta-angular. This version includes the class 'OktaAuthService'. My goal is to enhance this class by adding a new method using module augmentation.
My Approach So Far
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;
//
});
}
Although I referred to https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation for guidance, I encountered some issues:
The interface seems to be causing a problem with the import (TS2693 'OktaAuthService' only refers to a type, but is being used as a value here where the getUserRole function is defined)
If I exclude the new function but keep the module, compilation errors occur when importing from "@okta/okta-angular"
I'm seeking clarification on what I might be misunderstanding in this context.