Creating an Angular 2 and Typescript application.
I am facing an issue with an abstract class within an NPM package that I am trying to implement in my app code. Everything was functioning correctly until I introduced the public
isLoggedIn:Subject<boolean>;
property.
current-user.service.ts
@Injectable()
export abstract class CurrentUserContextService {
public isLoggedIn:Subject<boolean>;
public userId:string;
public userName:string;
public email:string;
public scope:string[];
constructor() { }
}
my-current-user.service.ts
@Injectable()
export class MyCurrentUserContextService implements CurrentUserContextService {
// defining interface properties.
public isLoggedIn:Subject<boolean>;
public userId: string;
public userName: string;
public email: string;
public scope: string[];
// additional custom properties can be added here.
constructor() { }
}
// additional custom methods can be implemented here.
}
main.ts
bootstrap(AppComponent, [
MyCurrentUserContextService,
{provide: CurrentUserContextService, useExisting: MyCurrentUserContextService}
])
Error
Encountering an error where 'MyCurrentUserContextFactoryService' is incorrectly implementing the interface 'CurrentUserContextFactoryService'. The types of property 'currentUserContext' are not compatible. The type 'MyCurrentUserContextService' cannot be assigned to type 'CurrentUserContextService'. The types of property 'isLoggedIn' are conflicting. Type 'Subject' cannot be assigned to type 'Subject'. The property 'destination' is protected whereas the type 'Subject' is not a subclass of 'Subject'.