강의

멘토링

커뮤니티

Inflearn Community Q&A

bano1124652's profile image
bano1124652

asked

[Renewal] TypeScript All-in-One: Part 1. Basic Grammar

forEach, map generic analysis

타입스크립트 교과서, p131

Resolved

Written on

·

249

·

Edited

0

여기서 Person3 결과로
Person: {

"name: "zero",

"age": 28,

married: false

}

이렇게 나와야 하는거 아닌가요??

전체 코드입니다.

class Person {
  name?: string;
  age?: number;
  married?: boolean;

  constructor();
  constructor(name: string, married: boolean);
  constructor(name: string, age: number, married: boolean);
  constructor(name?: string, age?: boolean | number, married?: boolean) {
    if (name) {
      this.name = name;
    }

    if (typeof age === "boolean") {
      this.married = age;
    } else {
      this.age = age;
    }

    if (married) {
      this.married = married;
    }
  }
}

const person1 = new Person();
const person2 = new Person("nero", true);
const person3 = new Person("zero", 28, false);

 

typescript

Answer 1

1

zerocho님의 프로필 이미지
zerocho
Instructor

코드 보시면 married가 true일 때만 this.married를 설정하도록 되어있습니다.

bano1124652's profile image
bano1124652

asked

Ask a question