반응형
    
    
    
  Intersection Types: &
type Student = {
    name: string;
    score: number;
  };
  type Worker = {
    empolyeeId: number;
    work: () => void;
  };
  function internWork(person: Student & Worker) {
    console.log(person.name, person.empolyeeId, person.work());
  }
  internWork({
    name: 'sein',
    score: 1,
    empolyeeId: 123,
    work: () => {},
  });모든것 And 와 비슷하다
Student & Worker 학생이면서 일을 하는 타입
함수를 사용 할 때는 모든 타입에 들어있는 키들을 모두 지정해줘야 한다.
오류가 생기지 않는다.
    name: 'sein',
    score: 1,
    empolyeeId: 123,
    work: () => {},모두 사용해줘야 한다.
반응형
    
    
    
  'Node > TypeScript' 카테고리의 다른 글
| 09. Inference 타입추론 (0) | 2021.04.20 | 
|---|---|
| 7.Union (0) | 2021.04.17 | 
| 6.Aliases (0) | 2021.04.15 | 
| 5.배열 Array or Tuple (0) | 2021.04.15 | 
| 4.함수 타입(JS →TS) (0) | 2021.04.15 | 
 
                    
                   
                    
                   
                    
                  