# TS - as Type Casting

<figure><img src="/files/6qjLKlmqDkQjLbP6hXWB" alt=""><figcaption></figcaption></figure>

TypeScript ရဲ့ `"as"` keyword ဟာ Type Assertion (Type Casting) လို့ခေါ်ပါတယ် ။

`someVariable as TargetType` ရေးသားနည်းနဲ့ ပြောင်းလဲစေချင်တဲ့ Type ကို Modify လုပ်နိုင်ပါတယ် ။

JSON parse နမူနာ Code ကို အရင်ကြည့်ရအောင် ... ။

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

JSON.parse method က any type ပဲ ပြန်ပေးပါတယ် ။&#x20;

ဒါကြောင့် responseData ထဲမှာ any ဖြစ်နေမှာပါ ။&#x20;

သို့ပေ့မယ် မိမိက User Type အနေနဲ့ ပြန်ရမယ်ဆိုတာ ကြိမ်းသေသိနေတဲ့ အခြေအနေမျိုးဖြစ်နေတဲ့အခါ ၊&#x20;

User Type အနေနဲ့ Type Casting လုပ်လိုက်တာ Type safe ပိုဖြစ်သွားမှာပါ ။

နောက်ပိုင်း `user` variable ကို သုံးတဲ့အခါ TypeScript Feedback တွေ သေချာရနိုင်သွားမှာပါ ။

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

များသောအားဖြင့် ဘယ်အခြေအနေတွေမှာ Type Assertion နည်းကို အသုံးများလဲဆိုရင် ၊&#x20;

unknown type နဲ့ any type ရလာတဲ့ အခါမျိုးတွေမှာ&#x20;

ကိုယ်ကလည်း ဘယ် 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-as-type-casting.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.
