Utility & Mapped Types မှာ caller နဲ့ implementation ကြား contract ကို minimal ဖြစ်အောင်ရေးပါ။ Generic constraints, variance, readonly data နဲ့ structural compatibility ကိုစဉ်းစားပြီး type assertion ဖြင့်အမှန်တရားကိုဖုံးမထားပါနှင့်။
ပိုပြီးနားလည်ထားရမယ့် အချက်
Utility & Mapped Types မှာ caller နဲ့ implementation ကြား contract ကို minimal ဖြစ်အောင်ရေးပါ။ Generic constraints, variance, readonly data နဲ့ structural compatibility ကိုစဉ်းစားပြီး type assertion ဖြင့်အမှန်တရားကိုဖုံးမထားပါနှင့်။
လက်တွေ့မှာ ဘယ်လိုအသုံးချမလဲ
Utility & Mapped Types example ကို strict mode ဖြင့် type-check လုပ်ပြီး valid, null/undefined, malformed API data, union variant အသစ်နဲ့ module boundary cases စမ်းပါ။ Type error ကို assertion သို့ any ဖြင့်ပိတ်မထားဘဲ contract သို့ validation ကိုပြင်ပါ။
ဒီသင်ခန်းစာပြီးရင်
type User = { id: string; name: string; email: string };
type UserPatch = Partial<Pick<User, 'name' | 'email'>>;
type Flags<T> = { readonly [K in keyof T]: boolean };
const changed: Flags<UserPatch> = { name: true, email: false };Source contract တစ်ခုမှ safe derived types များကို ပြန်သုံးနိုင်မည်။ကိုယ်တိုင်စမ်းကြည့်ရန်
Utility & Mapped Types 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 မှန်ပြီဟုယူဆခြင်း။
Utility Types — TypeScript