[TS] interface

지현·2022년 6월 16일
0

어떻게 type하는가 === component에게 type을 준다

🔵 Interface

interface : object shape을 TypeScript에게 설명해주는 TypeScript의 개념 (object가 어떤식으로 보일 지 설명)

interface InterfaceName {
  a: string,
  b: number;
}

function Component({a}:InterfaceName) {
  return <ConstName />;
}

오브젝트 형태로 type을 정의하고 component의 prop에 넣어준다

대부분 styled-component props와 component props를 따로 만든다.


🔵 InterfaceName

InterfaceName의 앞에 I를 붙여 interface인지 아닌지 구별할 수 있도록 쓰기도 한다.

data에 대한 interface를 생성한다고 가정한다면

interface IData {
  id: string
}

0개의 댓글