การกำหนด Type ในฟังก์ชั่น
Parameter Type
function say(word: string, times: number) {
[...Array(times).keys()].forEach(() => {
console.log(word)
})
}say("Very Good", 3) // OK
say("กล้ามาก", "เก่งมาก")
// Argument of type 'string' is not assignable to parameter of type 'number'.Return Type
function sum(a, b): number {
return a + b
}Last updated