더북(TheBook)

다음과 같이 클래스 표현식으로도 선언할 수 있습니다.

const Person = class {
  name;
  age;
  married;
  constructor(name: string, age: number, married: boolean) {
    this.name = name;
    this.age = age;
    this.married = married;
  }
}

멤버는 항상 constructor 내부와 짝이 맞아야 합니다.

class Person {
  name: string;
  married: boolean;
  constructor(name: string, age: number, married: boolean) {
    this.name = name;
    this.age = age;
  }
}
// Property 'married' has no initializer and is not definitely assigned in the constructor.
// Property 'age' does not exist on type 'Person'.