TypeScript เบื้องต้น – 3. Type Annotation vs Type Inference

type annotation คือกำหนด type ให้ตัวแปร, array , constant , object , function

let num : number

อันนี้เป็นการกำหนดให้เป็น number, แต่จะให้ค่าเป็น string ไม่ได้ num = “hello” ไม่ได้

Type Inference and Type Annotations in TypeScript


แยกระหว่าง type inferenece vs type annotation