interface A {
      name: string;
    }
    interface B {
      age: number;
    }
    
    function test(): A | B {
      if (Math.random() > 0.5) {
        return {
          age: 28,
        }
      }
      
      return {
        name: 'zero'
      }
    };
    const target1: A & B = test();
    // Type 'A | B' is not assignable to type 'A & B'
    const target2: A = test();
    // Type 'A | B' is not assignable to type 'A'
    const target3: B = test();
    // Type 'A | B' is not assignable to type 'B'
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.