UI/Javascript
[JS/Type] 더 명확한 작성법 함수 작성법
Soo_Parkle
2024. 5. 1. 14:26
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) { }