> For the complete documentation index, see [llms.txt](https://lwin-moe-paing.gitbook.io/typescript-baby-by-lwin-moe-paing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lwin-moe-paing.gitbook.io/typescript-baby-by-lwin-moe-paing/basic-typescript/ts-object.md).

# TS - Object

<figure><img src="/files/1J3RXu4Q2QYglD9pHtIT" alt=""><figcaption></figcaption></figure>

ရိုးရိုး JavaScript မှာလိုပဲ Object တစ်ခု Key-Value Pairs တွေနဲ့ တည်ဆောက်ပါတယ်

Object Type ကို ရေးသား ဖို့အတွက် TypeScript မှာ Property နဲ့ ValueType ကို သတ်မှတ်ရေးသားကြပါတယ် ။

### Object Type Annotation

<figure><img src="/files/vdwyAzfeI5NKD2sHPmbC" alt=""><figcaption></figcaption></figure>

const `person` ရဲ့နောက်မှာ object type အဖြစ် ဆိုင်ရာ property တွေနဲ့ type တွေ အရင်သတ်မှတ်လိုက်ပါတယ် ။ ပြီးတဲ့နောက်မှာ တန်ဖိုးကို Assign လုပ်လိုက်ပါတယ် ။ အောက်က Code အတိုင်းဖြစ်သွားမှာပါ ။

```typescript
const person: {
  name: string;
  age: number;
  status: "active" | "inactive";
} = {
  name: "Lwin",
  age: 28,
  status: "active",
};
```

စာဖတ်သူတို့က property အသစ် isAdmin (boolean) type ထည့်ပေးပါ ။&#x20;

အဖြေကတော့ အောက်ပါ Code အတိုင်း ရလာမှာဖြစ်ပါတယ် ။

```typescript
const person: {
  name: string;
  age: number;
  status: "active" | "inactive";
  isAdmin: boolean;
} = {
  name: "Lwin",
  age: 28,
  status: "active",
  isAdmin: true,
};
```

### Optional Properties

<figure><img src="/files/bKMVezmg11IMMxIIFDQj" alt=""><figcaption></figcaption></figure>

Object ထဲက တချို့ property တွေ မဖြည့်လည်း ရအောင် `?` (question mark) ကို သုံးနိုင်ပါတယ်။

နမူနာ code ထဲမှာ `age` , `status` ရယ်ကို `?:` သုံးပြီး ရေးသားလိုက်တဲ့အတွက်  Assign  မထည့်ဘဲ ရေးသားနိုင် သွားပါတယ်။
