React에서 TypeScript 올바르게 사용하기
React에서 TypeScript 올바르게 사용하기
Select 컴포넌트를 만든다고 가정해보자.
1 | const Select = ({ label, value, options, onChange }) => { |
1. 무지성으로 타입 정의
1 | const Select = ({ |
2. type, interface로 타입 정의
1 | type Option = { label: string; value: string }; |
3. 타입 파일 분리하기
1 | // Select.d.ts |
1 | // Select.tsx |
- 정답은 없지만 팀 내부에서 하나를 결정하고 통일할 필요는 있다.