typescript constructor shorthand

Solutions on MaxInterview for typescript constructor shorthand by the best coders in the world

showing results for - "typescript constructor shorthand"
Isabell
21 Sep 2017
1// Imagine you have following code, let’s say you have class User:
2
3class User {
4  private name: string;
5  private surname: string;
6  private age: number;
7
8  constructor(name: string, surname: string, age: number) {
9    this.name = name;
10    this.surname = surname;
11    this.age = age;
12  }
13}
14
15// You can write same class using shorter syntax:
16class User {
17  constructor(
18    private name: string,
19    private surname: string,
20    private age: number
21  ) {}
22}