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