Literal Types, as const & satisfies ကို annotation syntax အဖြစ်သာမမြင်ဘဲ JavaScript runtime value များ၏ဖြစ်နိုင်သော set, control-flow narrowing, nullability နဲ့ exhaustive checking ကိုဖော်ပြသော model အဖြစ်နားလည်ပါ။ Inference ကိုဦးစားပေးပြီး unsafe input ကို unknown မှစပါ။
ပိုပြီးနားလည်ထားရမယ့် အချက်
Literal Types, as const & satisfies ကို annotation syntax အဖြစ်သာမမြင်ဘဲ JavaScript runtime value များ၏ဖြစ်နိုင်သော set, control-flow narrowing, nullability နဲ့ exhaustive checking ကိုဖော်ပြသော model အဖြစ်နားလည်ပါ။ Inference ကိုဦးစားပေးပြီး unsafe input ကို unknown မှစပါ။
လက်တွေ့မှာ ဘယ်လိုအသုံးချမလဲ
Literal Types, as const & satisfies example ကို strict mode ဖြင့် type-check လုပ်ပြီး valid, null/undefined, malformed API data, union variant အသစ်နဲ့ module boundary cases စမ်းပါ။ Type error ကို assertion သို့ any ဖြင့်ပိတ်မထားဘဲ contract သို့ validation ကိုပြင်ပါ။
ဒီသင်ခန်းစာပြီးရင်
type Route = { path: string; secure: boolean };
const routes = {
home: { path: '/', secure: false },
account: { path: '/account', secure: true },
} as const satisfies Record<string, Route>;
const accountPath = routes.account.path; // '/account'Object ကိုစစ်ပေးသလို precise literal types များလည်းမပျောက်ပါ။ကိုယ်တိုင်စမ်းကြည့်ရန်
Literal Types, as const & satisfies example ကို strict mode ဖြင့် type-check လုပ်ပြီး valid, null/undefined, malformed API data, union variant အသစ်နဲ့ module boundary cases စမ်းပါ။ Type error ကို assertion သို့ any ဖြင့်ပိတ်မထားဘဲ contract သို့ validation ကိုပြင်ပါ။
Type Safety သတိပေးချက်
TypeScript compile အောင်ရုံဖြင့် API data နဲ့ runtime behavior မှန်ပြီဟုယူဆခြင်း။
TypeScript Handbook — TypeScript