# TS - Enum

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

Enum (Enumeration) ဆိုတာ မပြောင်းလဲနိုင်တဲ့ Constant Data အစုတွေအတွက် လွယ်အောင်လုပ်ပေးထားတဲ့ Type တစ်ခုပါ ။ ပြထားတဲ့ ပုံထဲကအတိုင်း အရင်ဆုံး enum keyword နဲ့ Enum တစ်ခုကို ပြုလုပ်နိုင်ပါတယ် ။ `Role` မှာ `USER` ရယ် `ADMIN` ရယ်ပဲ ရှိတဲ့အတွက် Role Enum တစ်ခုကို လုပ်လိုက်တာပါ ။ အဲ့ဒီ Enum တန်ဖိုးကို ယူချင်တဲ့အခါ variable တစ်ခုထဲကို Role.User ဆိုပြီး ယူလိုက်လို့ရပါတယ် ၊ အလိုအလျောက် သတ်မှတ်ပေးထားတဲ့ တန်ဖိုး 0 ကိုရသွားမှာပါ ။

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

စာဖတ်သူတို့က Role ထဲကို နောက်ထက် `SUPERVISOR` နဲ့ `SUPERADMIN` role ကို ထပ်တိုးကြည့်လိုက်ပြီး console.log နဲ့ မိမိစက်ထဲမှာ အဖြေရှာကြည့်ပါ ။

```typescript
enum Role {
  USER,
  SUPERVISOR,
  ADMIN,
  SUPERADMIN,
}
const userRole = Role.USER;
console.log(userRole);
```

အလိုအလျောက် 0 ကနေ အစဉ်လိုက်စီထားတဲ့ တန်ဖိုးတစ်ခုကို ရသွားမှာပဲဖြစ်ပါတယ် ။ လက်တွေ့မှာ  ကိုယ်သတ်မှတ်ချင်တဲ့ တန်ဖိုးကိုပဲ  အသုံးပြုကြတာများတယ် ။ ဒီ့အတွက် အောက်က Code အတိုင်း ကိုယ်ပိုင် တန်ဖိုးတွေ ထည့်သွင်းလုပ်ဆောင်နိုင်ပါတယ် ။

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

သတ်မှတ်ထားတဲ့ တန်ဖိုးကို `=` နဲ့ Assign လုပ်ပြီး ကိုယ်ပိုင်တန်ဖိုးတွေကို အသုံးပြုလို့ရပါတယ် ။

```typescript
enum Permission {
  CREATE = "CREATE",
  READ = "READ",
  UPDATE = "UPDATE",
  DELETE = "DELETE",
}
const readPermission = Permission.READ;
console.log(readPermission);
```

ဒီလိုနည်းနဲ့ Enum ကို အသုံးပြုပြီး Constant Data အစုအဖွဲ့ အဖြစ်အသုံးပြုကြလေ့ရှိပါတယ် ။&#x20;

စာရေးသူကိုယ်တိုင်ကတော့ Enum Type ကို သိပ်သုံးလေ့သုံးထမရှိပါဘူး ။


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lwin-moe-paing.gitbook.io/typescript-baby-by-lwin-moe-paing/basic-typescript/ts-enum.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
