TypeScript ထည့်သွင်းခြင်း

7.0.2

TypeScript က program မ run ခင် types စစ်ပါတယ်။ Type annotations က runtime မှာ ဝင်လာတဲ့ data ကို validate မလုပ်ပေးပါဘူး။

ဒီစာမျက်နှာမှာ

Project ထဲ ထည့်ပြီး စစ်ခြင်း

Team တစ်ခုလုံး compiler version တူတူသုံးဖို့ TypeScript ကို development dependency အဖြစ် ထည့်ပါ။ tsconfig.json နဲ့ စပါ။ Build files မထုတ်ဘဲ စစ်ချင်ရင် tsc --noEmit run ပါ။

npm install --save-dev typescript@7.0.2
npx tsc --init
npx tsc --noEmit

Strict Checking နှင့် Inference

Project အသစ်မှာ strict checking သုံးပါ။ TypeScript က values နဲ့ return expressions ကနေ type ကို ခန့်မှန်းပေးနိုင်ပါတယ်။ Function parameters နဲ့ export လုပ်တဲ့ contract လို နေရာတွေမှာ annotations ထည့်ပါ။

export function total(price: number, units: number) {
  return price * units;
}

const amount = total(3, 2); // inferred as number

တရားဝင် ကိုးကားချက်များ