더북(TheBook)

interface와 type 간에 교차 사용도 가능합니다.

interface IPerson<N, A> {
  type: 'human',
  race: 'yellow',
  name: N,
  age: A,  
}
type TPerson<N, A> = {
  type: 'human',
  race: 'yellow',
  name: N,
  age: A,  
}
type Zero = IPerson<'zero', 28>;
interface Nero extends TPerson<'nero', 32> {}

정리하면 제네릭은 다음과 같은 위치에 사용할 수 있습니다.

• interface 이름<타입 매개변수들> {...}

• type 이름<타입 매개변수들> = {...}

• class 이름<타입 매개변수들> {...}

• function 이름<타입 매개변수들>(...) {...}

• const 함수이름 = <타입 매개변수들>(...) => {...}