TypeScript, 객체 타입에 대한 함수 인자의 기본값 지정

type Shape = 'circle' | 'box';

interface PaintOptions {
  shape: Shape;
  xPos?: number;
  yPos?: number;
};

function paintShape({ shape, xPos = 0, yPos = 0 }: PaintOptions) {
  console.log(shape);
  console.log("x coordinate at", xPos);
  console.log("y coordinate at", yPos);                                  
}

paintShape({ shape: 'circle' });

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다