TypeScript class method context guide when using class inheritance with Angular services
Quick question that's been bugging me - I'm experiencing an scenario with method context when inheriting from a base service class in Angular. I have a base class `BaseService` with a method that relies on `this` to access properties. However, when I extend this class in `DerivedService`, the property access seems to be undefined. Here's a simplified version of my code: ```typescript // base.service.ts export class BaseService { protected property: string; constructor() { this.property = 'Hello from BaseService'; } public greet() { return this.property; } } // derived.service.ts import { BaseService } from './base.service'; export class DerivedService extends BaseService { constructor() { super(); } public greetDerived() { console.log(this.greet()); // This should access the base class method } } ``` When I create an instance of `DerivedService` and call `greetDerived()`: ```typescript const service = new DerivedService(); service.greetDerived(); ``` I expect to see 'Hello from BaseService', but I'm getting `undefined` instead. I've checked that the constructor of the base class is being called correctly, so I'm puzzled why `this.property` isn't accessible. I also tried using arrow functions for the methods, but that didn't change the behavior. Iām using TypeScript 4.5 and Angular 12. Could there be an scenario with how TypeScript handles method context in class inheritance? Any insights would be appreciated! I'm working on a service that needs to handle this. This is for a web app running on macOS.