본문 바로가기

나의 FE피봇이야기/Javascript

[JS/Type] 더 명확한 작성법 함수 작성법

  function createCourse(): { name: string; isPaid: boolean } { ... } function createCourse(): { name: string; isPaid: boolean } { ... }
Return Type Inferred from the object parameter Explicitly defined after a colon
Type Safety Less strict, potential for runtime errors Stricter, compiler checks for correct return type
Readability Less clear about the return type Clearer, self-documenting with explicit return type
     

 

 

But much a Better option

type User = {
  name : string,
  isPaid : boolean,
  email : string
}

function createUser(user : User) { }