shortand constructors typescript code example

Example: typescript constructor shorthand

// Imagine you have following code, let’s say you have class User:

class User {
  private name: string;
  private surname: string;
  private age: number;

  constructor(name: string, surname: string, age: number) {
    this.name = name;
    this.surname = surname;
    this.age = age;
  }
}

// You can write same class using shorter syntax:
class User {
  constructor(
    private name: string,
    private surname: string,
    private age: number
  ) {}
}