TS-2: Advanced Types
Advanced Types
Section titled “Advanced Types”หลังจากเข้าใจ type พื้นฐานแล้ว ขั้นต่อไปคือเครื่องมือขั้นสูงที่ช่วยให้เขียน type-safe code ที่ยืดหยุ่นและ reusable
เป้าหมายการเรียนรู้
Section titled “เป้าหมายการเรียนรู้”- เข้าใจ Generics และสามารถสร้าง generic functions, interfaces ที่ reusable ได้
- ใช้ Utility Types (Partial, Pick, Omit, Record ฯลฯ) ในการ transform types ได้อย่างคล่องแคล่ว
- เขียน Type Guards เพื่อ narrow types อย่างปลอดภัยทั้ง typeof, instanceof, in และ custom guards
Progress 0 / 3
ทำไม Advanced Types สำคัญ?
Section titled “ทำไม Advanced Types สำคัญ?”ในงานจริง เราเจอสถานการณ์ที่ basic types ไม่เพียงพอ:
- Reusable Components — component ที่ทำงานกับหลาย data types
- API Wrappers — function ที่ return type ขึ้นอยู่กับ input
- Form Handling — Partial updates, required fields ตามเงื่อนไข
- Runtime Validation — ตรวจสอบ type ณ runtime อย่างปลอดภัย
บทเรียนในบทนี้
Section titled “บทเรียนในบทนี้” 01 — Generics Generic functions, interfaces, constraints และ common patterns
02 — Utility Types Partial, Required, Pick, Omit, Record, Readonly, ReturnType
03 — Type Guards typeof, instanceof, in, custom type guards และ assertion functions
Lab: Type-safe API Handlers ฝึกปฏิบัติ: สร้าง API response handlers ที่ type-safe
Prerequisites
Section titled “Prerequisites”- ผ่าน TS-1: Type System พื้นฐาน
- เข้าใจ interfaces, union types และ type narrowing