# TypeScript Predicate Guard

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

"is" Type Predicates ကို type narrowing လုပ်ဖို့ အသုံးပြုပါတယ်။

function တစ်ခုက parameter တစ်ခုကို လက်ခံပြီး Narrowing လုပ်ဖို့အတွက် ကိုယ်ပြောင်းလဲချင်တဲ့ Target Type တစ်ခုကို သတ်မှတ်ပေးလိုက်တာဖြစ်ပါတယ် ။

ရေးသားနည်း Syntax အရ `(param: type) => param is TargetType ;` ဖြစ်ပေ့မယ်&#x20;

အမှန်တကယ် Return type က Boolean ပဲ ပြန်ရပါမယ် ။

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

နမူနာ Code မှာ `checkIsAdmin` ဆိုတဲ့ function ရှိပါတယ် ။&#x20;

ရည်ရွယ်ချက်က checkIsAdmin ကို ခေါ်လိုက်တာနဲ့ လက်ခံလိုက်တဲ့ user parameter အခြေအနေက true ဖြစ်ခဲ့ရင် သူ့ရဲ့ `Type` ကို AdminUser type အဖြစ်ပြောင်းပေးလိုက်မှာပါ ။

`actionForAdmin` မှာ လက်ခံထားတဲ့ user parameter က အစမှာ AdminUser (သို့မဟုတ် | ) Normal User ပါ ။

if ( checkIsAdmin(user) ) block အတွင်းမှာ user ကို mouse ဖြင့် ထောက်ပြီး ကြည့်ကြည့်တဲ့အခါ AdminUser type အဖြစ် Assertion လုပ်သွားမှာဖြစ်ပါတယ် ။


---

# 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/other-topic/typescript-predicate-guard.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.
