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

Type Guards

Type Guards คือเทคนิคที่ใช้ตรวจสอบ types ที่ runtime เพื่อให้ TypeScript narrow types ลงได้ ช่วยให้เข้าถึง properties และ methods ได้อย่างปลอดภัย

ประเภทSyntaxใช้กับ
typeoftypeof x === "string"Primitives
instanceofx instanceof DateClasses
in"prop" in objObject properties
Predicatex is TypeCustom functions
Assertionasserts x is TypeThrow if false
Diagram

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

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