객체의 구조(필드명, 타입)를 정의
변수, 함수 등에서 재사용 가능하고
새로운 객체를 생성할 때 컴파일 단계에서 필드명과 그 타입을 강제하여 안정성 확보 가능
interface User {
id: number;
name: string;
email: string;
}
인터페이스를 사용하지 않을 때
const createUser = ({ id, name, email }: {
id: number;
name: string;
email: string;
}) => {
// 내부 로직 구현
}
인터페이스로 간소화 가능
const createUser = (user: User) => {
// 내부 로직 구현
}