const Assertions
const assertions (as const) ทำให้ TypeScript infer types แบบ literal แทน wide types และทำให้ค่าเป็น readonly ช่วยสร้าง type-safe constants
ผลของ as const
Section titled “ผลของ as const”| ไม่มี as const | มี as const |
|---|---|
string | "hello" (literal) |
number | 42 (literal) |
string[] | readonly ["a", "b"] |
{ x: number } | { readonly x: 42 } |
Const Assertion Flow
Section titled “Const Assertion Flow”เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม
ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด
Login with Google