본문 바로가기

UI/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) { }

'UI > Javascript' 카테고리의 다른 글

[JS/Type] interface and type  (0) 2024.05.02
[JS] return new Response  (0) 2024.05.01
[JS/Type] void (update : 2024.04)  (0) 2024.04.30
[JS] How Promise works  (0) 2024.04.09
[Javascript/Json] Json 데이터를 만들기 위한 크롤링  (0) 2024.04.02