10.1 막강한 타입들 소개 (advanced types)

10.2 Type(Alias)와 Interface, 뭘 써야 할까?(기술 관점)

배경

공통점과 차이점 (type과 interface로 할 수 있는것들, 할 수 없는 것들)

{
  type PositionType = {
    x: number;
    y: number;
  };
  // type PositionType = { // error
  //   z: number;
  // }
  interface PositionInterface {
    x: number;
    y: number;
  }
  // 😆 only interfaces can be merged.
  interface PositionInterface {
    z: number;
  }
	... 
}

{
	...
  // object ★
  const obj1: PositionType = {
    x: 1,
    y: 1,
  };
  const obj2: PositionInterface = {
    x: 1,
    y: 1,
    z: 1,
  };

  // class ★
  class Pos1 implements PositionType {
    x: number;
    y: number;
  }
  class Pos2 implements PositionInterface {
    x: number;
    y: number;
    z: number;
  }

  // Extends
  type ZPositionType = PositionType & { z: number };
  
  interface ZPositionInterface extends PositionInterface {
    z: number;
  }

  ...
}
{
	...
  // 😆 Type aliases can use computed properties 
  // (e.g. Mapped, Utility, Index types)
  type Person = {
    name: string;
    age: number;
  };
  type Name = Person['name']; // string

	// others..
  type NumberType = number;
  type Direction = 'left' | 'right';
}

10.3 Type(Alias)와 Interface, 뭘 써야 할까?(개념 관점)

Interface