TypeScript class using private fields not reflecting updates in subclass methods
I'm working on a TypeScript project where I'm trying to create a base class with private fields, and I'm working with an scenario with subclass methods not reflecting updates to these fields. Here's a simplified version of my code: ```typescript class Base { private value: number; constructor(initialValue: number) { this.value = initialValue; } public getValue(): number { return this.value; } protected setValue(newValue: number): void { this.value = newValue; } } class Sub extends Base { public incrementValue(increment: number): void { const currentValue = this.getValue(); // behavior here this.setValue(currentValue + increment); } } const instance = new Sub(10); instance.incrementValue(5); console.log(instance.getValue()); // Expecting 15 ``` When I run this code, I get a TypeScript behavior saying `Property 'setValue' is protected and only accessible within class 'Base' and its subclasses`. I assumed that since `Sub` extends `Base`, I would have access to `setValue`, but it seems like the private `value` field is not being updated correctly in the context of the subclass. I also tried changing `private` to `protected` for the `value` field, but that didn’t seem to solve the question. I’ve also checked my TypeScript version, which is 4.5.4. Am I misunderstanding how private fields work in TypeScript, or is there a different way I should be handling this? Any guidance would be appreciated!