FrontEnd/TypeScript2 [ TypeScript ] Type vs Interface 타입스크립트를 공부하다보면, interface 와 type 의 차이에 대해 한 번쯤은 고민하게 되는 것 같다. 둘 다 같은 기능을 하는 것 같은데 왜 두 가지나 있을까? 차이점은 뭐가 있을까? Type, Interface 란? Type Aliases : a name for any type (objects & others) Interface : a name for object type type Point = { x: number; y: number; }; // 가능 type ID = number | string; // 가능 type UserInputSanitizedString = string; // 가능 interface Point { x: number; y: number; } //가능 Type vs In.. 2023. 11. 4. [ TypeScript ] Props 타입 지정하기 interface SectionContainerProps { newsArr : NewsData[] ; } export default function SectionContainer({newsArr}:SectionContainerProps) { ... } export default function SectionContainer({newsArr}:{newsArr:NewsData[]}) { } export default function SectionContainer({newsArr}) { const newsData = newsArr as NewsData[] // 사용할 데이터 이름으로 변수 선언 ... } 2023. 10. 26. 이전 1 다음