Skip to content
เข้าสู่ระบบ

Basic Types

TypeScript เพิ่ม Type System เข้ามาใน JavaScript เพื่อช่วยตรวจจับ bugs ตั้งแต่ตอนเขียนโค้ด ไม่ต้องรอจนกว่าจะ run แล้วพัง

ข้อดีคำอธิบาย
Catch Errors Earlyเจอ bug ตั้งแต่ตอนเขียน ไม่ใช่ตอน production
Better IDE SupportAutocomplete, refactoring ทำงานได้ดีกว่า
Self-documentingอ่านโค้ดแล้วรู้เลยว่าตัวแปรเก็บอะไร
Safer Refactoringเปลี่ยนโค้ดแล้วรู้ทันทีว่าตรงไหนพัง
Diagram

TypeScript ทำ static type-checking ตอน compile ไม่ใช่ตอน runtime:

// JavaScript พัง runtime
const message = "Hello!";
message(); // TypeError: message is not a function
// TypeScript เจอตอน compile
const message: string = "Hello!";
// message(); // Error: This expression is not callable.

เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม

ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด