> 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-keyof.md).

# TS - keyof

<figure><img src="https://4062235122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7tekcoDYDaKhlNreT5uK%2Fuploads%2FZQgAsrUCOacavwAFJ6ZQ%2FTypescript%20keyof%20Syntax.png?alt=media&amp;token=d4d79e6a-98e8-42fe-8372-8bf5ae7a9541" alt=""><figcaption></figcaption></figure>

Typescript မှာ `keyof` က Object တစ်ခုရဲ့ Keys (Property Names) တွေကို Union Type တစ်ခုအဖြစ်ပြန်ထုတ်ပေးနိုင်ပါတယ် ။  `keyof ObjectType` ရေးထုံးနဲ့ String Union တွေကို ရရှိသွားမှာပါ ။&#x20;

<figure><img src="https://4062235122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7tekcoDYDaKhlNreT5uK%2Fuploads%2FpqeI2nivmdKINmTZUutw%2FTypescript%20keyof%20Example.png?alt=media&amp;token=dba71a15-3379-4a73-87d4-e3d6e064e887" alt=""><figcaption></figcaption></figure>

နမူနာ Code ထဲမှာ `id`, `name`, `age` အစရှိတဲ့ propery တွေကို `keyof User` နဲ့ ထုတ်ယူလိုက်နိုင်ပါတယ် ။

<figure><img src="https://4062235122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7tekcoDYDaKhlNreT5uK%2Fuploads%2FgSk4glVCjA5kQmqCnRCx%2FTypescript%20keyof%20Example%20Code.png?alt=media&amp;token=00411e52-3cec-4198-b30a-1222044fafce" alt=""><figcaption></figcaption></figure>

TypeScript server က လည်း "id" | "age" | "name" တွေကို Feedback ပေးသွားမှာဖြစ်ပါတယ် ။&#x20;

အခု ရေးသားနည်းအရ `UserKeys`  Type တစ်ခု ခွဲထုတ်ရေးသားထားခြင်းဖြစ်ပါတယ် ။&#x20;

တိုက်ရိုက် `keyof User` ပုံစံနဲ့လည်း အသုံးပြုနိုင်တာကို လေ့လာကြည့်ပါမယ် ။

<figure><img src="https://4062235122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7tekcoDYDaKhlNreT5uK%2Fuploads%2FMVUUY6XkjbqY48RylKsZ%2FTypescript%20keyof%20Example%20Code%202.png?alt=media&amp;token=05e8cac8-9ec1-401b-a29a-21a6e328a4da" alt=""><figcaption></figcaption></figure>

type အသစ် မကြေငြာတော့ပဲ တိုက်ရိုက် constant `oneOfUserKeys` အနောက်မှာ keyof syntax နဲ့ ရေးသားလိုက်တာကို မြင်ရမှာပါ ။ keyof အကြောင်းအရာက ဒီလောက်ပဲဖြစ်ပါတယ် ။
