ရိုးရိုးလေး ရှင်းပြမယ်
Intro to TypeScript ကို ရိုးရိုးလေးနားလည်မယ်
Angular မှာ TypeScript ကိုအဓိကအသုံးပြုပါတယ်။ TypeScript က JavaScript ပေါ်မှာ type system, interface, class structure စတာတွေ ထပ်ပေါင်းထားတဲ့ language ဖြစ်လို့ project ကြီးလာတဲ့အခါ mistake တွေကို စောစောဖမ်းနိုင်ပါတယ်။ အထူးသဖြင့် API data, form value, component input/output တွေမှာ type ထည့်ရေးခြင်းက code ကိုပိုယုံကြည်ရစေပါတယ်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
`any` သုံးပြီး compiler error ပျောက်အောင်လုပ်ခြင်းက error ကို runtime ဆီရွှေ့တာသာဖြစ်ပါတယ်။
ဖြစ်လေ့ရှိတဲ့အမှား
Happy path တစ်ခုအောင်တာနဲ့ feature မှန်ပြီဟုယူဆခြင်းက empty, loading, error နဲ့ cleanup bugs များကိုလွတ်စေနိုင်ပါတယ်။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Angular code ရဲ့ contract များကို TypeScript interfaces, unions, generics နဲ့ strict null checks က compile time မှာကူညီစစ်ပေးပါတယ်။ Type annotation က runtime validation မဟုတ်သဖြင့် API/user input ကဲ့သို့ external data ကိုသီးခြား validate လုပ်ရပါတယ်။ `any` ကိုရှောင်ပြီး `unknown` ကို narrow လုပ်ခြင်း၊ readonly data နဲ့ explicit return types သုံးခြင်းက refactoring ကိုပိုလုံခြုံစေပါတယ်။
- Input + state
- Component + template
- Rendered Angular UI
Intro to TypeScript ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
// TypeScript allows us to add types to our variables.
let name: string = "Angular";
let version: number = 16;
let isAwesome: boolean = true;
function greet(person: string): string {
return "Hello, " + person;
}Angular code ရဲ့ contract များကို TypeScript interfaces, unions, generics နဲ့ strict null checks က compile time မှာကူညီစစ်ပေးပါတယ်။ Type annotation က runtime validation မဟုတ်သဖြင့် API/user input ကဲ့သို့ external data ကိုသီးခြား validate လုပ်ရပါတယ်။ `any` ကိုရှောင်ပြီး `unknown` ကို narrow လုပ်ခြင်း၊ readonly data နဲ့ explicit return types သုံးခြင်းက refactoring ကိုပိုလုံခြုံစေပါတယ်။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Input + state
// TypeScript allows us to add types to our variables.Angular မှာ TypeScript ကိုအဓိကအသုံးပြုပါတယ်။ TypeScript က JavaScript ပေါ်မှာ type system, interface, class structure စတာတွေ ထပ်ပေါင်းထားတဲ့ language ဖြစ်လို့ project ကြီးလာတဲ့အခါ mistake တွေကို စောစောဖမ်းနိုင်ပါတယ်။ အထူးသဖြင့် API data, form value, component input/output တွေမှာ type ထည့်ရေးခြင်းက code ကိုပိုယုံကြည်ရစေပါတယ်။
- Component + template
let isAwesome: boolean = true;Angular code ရဲ့ contract များကို TypeScript interfaces, unions, generics နဲ့ strict null checks က compile time မှာကူညီစစ်ပေးပါတယ်။ Type annotation က runtime validation မဟုတ်သဖြင့် API/user input ကဲ့သို့ external data ကိုသီးခြား validate လုပ်ရပါတယ်။ `any` ကိုရှောင်ပြီး `unknown` ကို narrow လုပ်ခြင်း၊ readonly data နဲ့ explicit return types သုံးခြင်းက refactoring ကိုပိုလုံခြုံစေပါတယ်။
- Rendered Angular UI
}User model နဲ့ loading/success/error union state တစ်ခုရေးပြီး invalid property access ကို compiler ကဖမ်းကြောင်းစမ်းပါ။ JSON response တစ်ခုကို runtime guard ဖြင့်စစ်ပါ။
- Input + state
- Component + template
- Rendered Angular UI
Success
Intro to TypeScript ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
Failure
`any` သုံးပြီး compiler error ပျောက်အောင်လုပ်ခြင်းက error ကို runtime ဆီရွှေ့တာသာဖြစ်ပါတယ်။
Angular မှာ TypeScript ကိုအဓိကအသုံးပြုပါတယ်။ TypeScript က JavaScript ပေါ်မှာ type system, interface, class structure စတာတွေ ထပ်ပေါင်းထားတဲ့ language ဖြစ်လို့ project ကြီးလာတဲ့အခါ mistake တွေကို စောစောဖမ်းနိုင်ပါတယ်။ အထူးသဖြင့် API data, form value, component input/output တွေမှာ type ထည့်ရေးခြင်းက code ကိုပိုယုံကြည်ရစေပါတယ်။
// TypeScript allows us to add types to our variables.
let name: string = "Angular";
let version: number = 16;
let isAwesome: boolean = true;
function greet(person: string): string {
return "Hello, " + person;
}(TypeScript သည် compile time တွင် error များကိုစစ်ဆေးပေးပြီး JavaScript သို့ compile လုပ်သည်)Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
User model နဲ့ loading/success/error union state တစ်ခုရေးပြီး invalid property access ကို compiler ကဖမ်းကြောင်းစမ်းပါ။ JSON response တစ်ခုကို runtime guard ဖြင့်စစ်ပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Intro to TypeScript နမူနာကို copy မလုပ်ဘဲ ကိုယ်တိုင်ပြန်ရေးပါ။ Normal state နှစ်ခု၊ edge case တစ်ခုနှင့် failure state တစ်ခုထည့်ပြီး expected UI နဲ့ state transition ကိုမ run မီရေးထားပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
// TypeScript allows us to add types to our variables.
let name: string = "Angular";
let version: number = 16;
let isAwesome: boolean = true;
function greet(person: string): string {
return "Hello, " + person;
}ရလဒ်: Intro to TypeScript ရဲ့ core concept နဲ့ Angular data flow ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
User model နဲ့ loading/success/error union state တစ်ခုရေးပြီး invalid property access ကို compiler ကဖမ်းကြောင်းစမ်းပါ။ JSON response တစ်ခုကို runtime guard ဖြင့်စစ်ပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Input + state → Component + template → Rendered Angular UI
- Angular code ရဲ့ contract များကို TypeScript interfaces, unions, generics နဲ့ strict null checks က compile time မှာကူညီစစ်ပေးပါတယ်။ Type annotation က runtime validation မဟုတ်သဖြင့် API/user input ကဲ့သို့ external data ကိုသီးခြား validate လုပ်ရပါတယ်။ `any` ကိုရှောင်ပြီး `unknown` ကို narrow လုပ်ခြင်း၊ readonly data နဲ့ explicit return types သုံးခြင်းက refactoring ကိုပိုလုံခြုံစေပါတယ်။
- `any` သုံးပြီး compiler error ပျောက်အောင်လုပ်ခြင်းက error ကို runtime ဆီရွှေ့တာသာဖြစ်ပါတယ်။
- User model နဲ့ loading/success/error union state တစ်ခုရေးပြီး invalid property access ကို compiler ကဖမ်းကြောင်းစမ်းပါ။ JSON response တစ်ခုကို runtime guard ဖြင့်စစ်ပါ။
TypeScript — Handbook — Microsoft