Answers for "typescript constructor shorthand"

1

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
  ) {}
}
Posted by: Guest on November-04-2020

Code answers related to "TypeScript"

Browse Popular Code Answers by Language