Constructor assignment of field variables in TypeScript

1 · Amit Merchant · June 15, 2021, 4:01 p.m.
When you work with classes with constructors in TypeScript, the usual way to declare the field variables is like following. class Book { private name: string; private author: string; constructor( name: string, author: string ) { this.name = name; this.author = author; } } As you can tell, using this approach you will have to declare class field variables at three different places. In the property declaration. In the constructor parameters. ...