Discriminated Unions
Discriminated Unions (หรือ Tagged Unions) คือ pattern ที่ใช้ common property เป็น “discriminant” เพื่อแยกแยะ types ใน union ทำให้ TypeScript narrow types ได้อัตโนมัติ
ข้อดีของ Discriminated Unions
Section titled “ข้อดีของ Discriminated Unions”| ข้อดี | คำอธิบาย |
|---|---|
| Type Safety | TypeScript narrow types อัตโนมัติ |
| Exhaustive | ตรวจสอบว่าจัดการครบทุก case |
| Readability | โค้ดอ่านง่าย เข้าใจ intent |
| Refactoring | เพิ่ม case ใหม่ได้ปลอดภัย |
Discriminated Union Flow
Section titled “Discriminated Union Flow”เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม
ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด
Login with Google