Javascript&Typescript
[Typescript] function
clolee
2024. 2. 13. 23:21
- 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}`
})
코드 :
참고 :