# TS - typeof

### typeof&#x20;

`typeof` ကို JavaScript runtime မှာ သုံးမယ်ဆိုရင် variable ရဲ့ type ကို `string` အနေနဲ့ return ပြန်ပါမယ်။

TypeScript ရေးသားနည်းမှာ `typeof` ကို သုံးမယ်ဆိုရင်တော့ variable ရဲ့ Type Structure ကို ပြန်ရမှာဖြစ်ပါတယ် ။

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

အခု နမူနာ Code ထဲကအတိုင်း `typeof user` က JavaScript Runtime မှာဆို "object" ဆိုတဲ့ String ကိုရသွားမှာပါ ။ &#x20;

TypeScript ရေးသားနည်းမှာ  `typeof variable` ပုံစံနဲ့  Object Structure ကို `CustomType` အဖြစ် ပြုလုပ်နိုင်ပါတယ် ။

`appConfig` Code ကို လေ့လာသွားကြပါမယ် ။&#x20;

ပထမဆုံး `appName` နဲ့ `env` property တွေပါတဲ့ appConfig ဆိုတဲ့ constant variable တည်ဆောက်ထားပါတယ် ။

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

Custom Type တစ်ခုအဖြစ် `ConfigType` ကို constant appConfig က တဆင့် `typeof appConfig` သုံးပြီး ပြုလုပ်လိုက်ပါတယ် ။

အခြား `devConfig` နဲ့ `prodConfig`  Config Variables တွေအတွက်  Reusable Type အဖြစ် အသုံးပြုနိုင်သွားပါပြီ ။

Type တွေကို ကိုယ်တိုင် သတ်မှတ်တာမဟုတ်ဘဲ Variable ဆီက Type ကို ပုံတူပွားတာမျိုး ဖြစ်တဲ့အတွက် အသုံးများပါတယ်။

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

Custom Type မတည်ဆောက်တော့ပဲ တိုက်ရိုက် `variable: typeof otherVariable`  အခုလိုပုံစံမျိုးနဲ့လည်း ရေးသားတာမျိုး ရှိပါတယ် ။ ဒါက ရိုးရှင်းတဲ့ Type Alias တစ်မျိုးပဲဖြစ်ပါတယ် ။

### keyof typeof တွဲရေးခြင်း

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

ဒါကလည်း အသုံးများတဲ့ ပုံစံလေးဖြစ်ပါတယ် ။&#x20;

`typeof` ကို သုံးလိုက်တဲ့အခါ variable ရဲ့ Type Structure ကိုရသွားမှာပါ ။&#x20;

ပြီးတော့မှ သူ့ရဲ့ အရှေ့မှာ keyof နဲ့ union keys တွေကို ထုတ်ယူလိုက်တာပဲဖြစ်ပါတယ် ။


---

# 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-typeof.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.
