부트캠프교육중/TypeScript

[TS] 유니언타입(|)과 인터섹션타입(&) 차이

뭉지야 2023. 8. 15. 14:05
728x90
let seho3: string | number | boolean;

let capt: string & number & boolean;

 

interface Developer {
    name: string;
    skill: string;
}

interface Person {
    name: string;
    age: number;
}


function askSomeone(someone: Developer | Person){
    someone.name
}

 

interface Developer {
    name: string;
    skill: string;
}

interface Person {
    name: string;
    age: number;
}

function askSomeone2 (someone: Developer & Person){
    someone.name;
    someone.skill;
    someone.age;
}

 

askSomeone({ name: '디벨로퍼', skill: '웹 개발' });
askSomeone({ name: '캡틴', age: 34 });

askSomeone2({ name: '알라라숑', skill: '피아노', age: 50 });

 

728x90