Conditional Types & infer မှာ caller နဲ့ implementation ကြား contract ကို minimal ဖြစ်အောင်ရေးပါ။ Generic constraints, variance, readonly data နဲ့ structural compatibility ကိုစဉ်းစားပြီး type assertion ဖြင့်အမှန်တရားကိုဖုံးမထားပါနှင့်။
ပိုပြီးနားလည်ထားရမယ့် အချက်
Conditional Types & infer မှာ caller နဲ့ implementation ကြား contract ကို minimal ဖြစ်အောင်ရေးပါ။ Generic constraints, variance, readonly data နဲ့ structural compatibility ကိုစဉ်းစားပြီး type assertion ဖြင့်အမှန်တရားကိုဖုံးမထားပါနှင့်။
လက်တွေ့မှာ ဘယ်လိုအသုံးချမလဲ
Conditional Types & infer example ကို strict mode ဖြင့် type-check လုပ်ပြီး valid, null/undefined, malformed API data, union variant အသစ်နဲ့ module boundary cases စမ်းပါ။ Type error ကို assertion သို့ any ဖြင့်ပိတ်မထားဘဲ contract သို့ validation ကိုပြင်ပါ။
ဒီသင်ခန်းစာပြီးရင်
type AwaitedResult<T> = T extends Promise<infer Value> ? Value : T;
type ApiResult = AwaitedResult<Promise<{ id: string }>>;
const item: ApiResult = { id: 'task-1' };ApiResult သည် Promise အတွင်း value type ဖြစ်သွားမည်။ကိုယ်တိုင်စမ်းကြည့်ရန်
Conditional Types & infer 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 မှန်ပြီဟုယူဆခြင်း။
Conditional Types — TypeScript