두 객체가 있고 속성이 동일할 때, 속성이 옵셔널인 객체가 옵셔널이지 않은 객체보다 더 넓은 타입입니다.

    type Optional = {
      a?: string;
      b?: string;
    };
    type Mandatory = {
      a: string;
      b: string;
    };
    const o: Optional = {
      a: 'hello',
    };
    const m: Mandatory = {
      a: 'hello',
      b: 'world',
    };
    const o2: Optional = m;
    const m2: Mandatory = o;
    // Type 'Optional' is not assignable to type 'Mandatory'. Types of property 'a' are incompatible. Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.
    
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.