<aside> ✅ Typescript는 정적 타입 지정을 제공합니다. 이로인해 타입을 명시적으로 선언할 수 있습니다. 이로인해 코드의 안정성이 높아지고 , 오류를 더 쉽게 찾을 수 있다는 장점이 있습니다. 진행했던 프로젝트에서는 Typescript의 자동완성, 타입 검사를 이용하여 효율적으로 코드를 작성하고, 오류를 빠르게 식별하며 큰 프로젝트들을 쉽게 관리할 수 있는 기반이 되었습니다.
</aside>
export interface IProfileDetails {
avatar: string
fName: string
lName: string
company: string
contactPhone: string
companySite: string
country: string
language: string
timeZone: string
currency: string
communications: {
email: boolean
phone: boolean
}
allowMarketing: boolean
}
Interface를 사용함으로써 Typescript 컴파일러가 타입의 객체를 다룰때 타입을 엄격하게 검사할 수 있습니다. 이는 휴먼에러를 방지하는 장점이 있습니다. 또한 데이터 구조의 ‘계약’ 역활을 합니다. 이 계약을 통해 개발자들은 제공되어야 하는 데이터의 타입이 무엇인지 명확히 알 수 있습니다. 실무프로젝트에선 협업하는 팀원들이 일관된 데이터 구조를 유지하는데 도움을 줍니다.
데이터베이스에는 Postgres를 사용합니다. Postgres 시작에 대한 가이드를 보려면 이 설명서를 확인하세요.
// 사용자 프로필 인터페이스 정의
interface UserProfile {
userId: number;
userName: string;
isActive: boolean;
}
// 사용자 프로필 생성 함수
function createUserProfile(userId: number, userName: string, isActive: boolean): UserProfile {
return { userId, userName, isActive };
}
// 올바른 타입의 인수를 사용하여 함수 호출
const userProfile = createUserProfile(1, 'JohnDoe', true);
console.log(userProfile);
타입명시를 통해 ‘createUserProfile’ 함수는 정확한 타입의 인수를 받아야 하며, 이런 액션들은 런타임 오류를 줄여줍니다. 타입스크립트에서는 변수나 함수의 속성을 자동으로 완성해줍니다. 또한 인터페이스를 사용하면 데이터구조가 명확해져 유지관리가 편해집니다.