In JavaScript ES6, classes support different types of members, such as methods and properties. TypeScript enriches that by bringing fields, read-only fields, and static members. Consider the following example:
class SumCalculator { static readonly supportedOperand = Operand.Sum; private _history: Calculable[] = []; get history() { return this._history; } set history(value: Calculable[]) { this._history = value || []; } constructor(private readonly logPrefix: string) { } logHistory() { console.log( `${this.logPrefix}: current history length: ${this.history.length}`); }}console.log(SumCalculator.supportedOperand);const calc = new SumCalculator(‘MyApp');calc.history = [{left: 2, right: 3}];calc.logHistory();
In the preceding code, you ...