Angular 2 & Typescript app.
I have an abstract class inside an NPM package that I am trying to provide implementation for inside my app code. This all worked fine until I added 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 {
// interface properties.
public isLoggedIn:Subject<boolean>;
public userId: string;
public userName: string;
public email: string;
public scope: string[];
// add custom properties as needed.
constructor() { }
}
// add custom methods as needed.
}
main.ts
bootstrap(AppComponent, [
MyCurrentUserContextService,
{provide: CurrentUserContextService, useExisting: MyCurrentUserContextService}
])
Error
Class 'MyCurrentUserContextFactoryService' incorrectly implements interface 'CurrentUserContextFactoryService'. Types of property 'currentUserContext' are incompatible. Type 'MyCurrentUserContextService' is not assignable to type 'CurrentUserContextService'. Types of property 'isLoggedIn' are incompatible. Type 'Subject' is not assignable to type 'Subject'. Property 'destination' is protected but type 'Subject' is not a class derived from 'Subject'.
extendsinstead ofimplements? - Harry Ninhclass, notinterface, andimplementsshould be using forinterfaceonly. So why don't you separate those you want the dev to implement to anotherinterface, and keep those concrete base implementation in the current base class? - Harry Ninh