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

const Assertions

const assertions (as const) ทำให้ TypeScript infer types แบบ literal แทน wide types และทำให้ค่าเป็น readonly ช่วยสร้าง type-safe constants

ไม่มี as constมี as const
string"hello" (literal)
number42 (literal)
string[]readonly ["a", "b"]
{ x: number }{ readonly x: 42 }
Diagram

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

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