Thuta Learning
ရှာဖွေရန်
AdvancedProgrammingintermediate

Interfaces

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Interface သည် object တစ်ခု၏ shape ကို သတ်မှတ်ရန် အစွမ်းထက်သော နည်းလမ်းတစ်ခုဖြစ်သည်။ ၎င်းသည် object တွင် မည်သည့် properties နှင့် methods များ ပါဝင်ရမည်ကို "contract" (သဘောတူညီချက်) အဖြစ် သတ်မှတ်ပေးသည်။

typescript
interface User {
  name: string;
  id: number;
  is_admin?: boolean; // Optional property
}

function printUser(user: User) {
  console.log(`User: ${user.name} (ID: ${user.id})`);
}

let myUser: User = { name: "Alice", id: 123 };
printUser(myUser);
You should see
User: Alice (ID: 123)
Interfaces | Thuta Learning