TS - Index Type
Last updated
Last updated
TypeScript မှာ Index Signature ဆိုတာက object properties တွေကို dynamic key အနေနဲ့သုံးနိုင်ဖို့ သတ်မှတ်ပေးတဲ့ concept တစ်ခုပဲဖြစ်ပါတယ် ။ ရေးသားနည်း [index: KeyType]
က property type သတ်မှတ်တာဖြစ်ပြီး (:)
အနောက်မှာ value type တွေကိုသတ်မှတ်တာပဲဖြစ်ပါတယ် ။
နမူနာ code အရ [index: number]: string
ရေးသားထားတာက keys တွေအားလုံး number type
ဖြစ်ပြီး value တွေက string type
ဖြစ်မယ်လို့ သတ်မှတ်ထားတာပါ ။
စာဖတ်သူတို့က key ကို string
type ထားပြီး value ကို booelan
type အဖြစ် မိမိ စက်ထဲမှာ ရေးသားကြည့်ပေးပါ ။
အဖြေက အောက်က Code အတိုင်း ဖြစ်မှာပါ ။