본문 바로가기
Javascript&Typescript

[Typescript] function

by clolee 2024. 2. 13.

- parameter type


      
function addTwo(num: number) {
return num + 2;
}
function getUpper(val: string){
return val.toUpperCase()
}

 

typescript error

 

 

- return type


      
function addTwo(num: number): number {
// return num + 2;
return "hello"
}

 

문자열로 변환 해 return. return type 통일하기


      
const heros = ["thor", "spiderman", "ironman"]
// const heros = [1, 2, 3]
heros.map((hero): string => {
return `hero is ${hero}`
})

 

 

코드 :

 

참고 :

 

댓글