• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    해결됨

object intersection에서 유니언으로 타입 질문

24.03.10 13:57 작성 조회수 45

1

type CompanyOrPet = PersonType | (CompanyType|PetType);
type CompanyOrPet2 = PersonType | CompanyType | PetType;

const companyOrPet: CompanyOrPet2 = {
    // PersonType
    name: 'DD',
    age: 27,
    
    // CompanyType
    company:'GK',
    companyRegistrationNumber:'asfasfasfasf',

    //PetType
    petName:'Ori',
    petAge:4,
}

강의에서는 CompanyOrPet 타입으로 PersonType, CompanyType, PetType을 포함할 수 있는 타입으로 만들어서 객체를 만들셔서 어느 하나의 타입만 충족되더라고 에러없이 객체가 생성되도록 하셨는데 CompanyOrPet과 CompanyOrPet2의 차이점이 있나요?

답변 1

답변을 작성해보세요.

0

안녕하세요!

차이가 없어보입니다!

감사합니다!