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)