Interface trong typescript cũng tương tự như trong các ngôn ngữ lập trình hướng đối tượng khác. Ví dụ:
//USER INTERFACE
interface User {
name: string;
age: number;
address: string
}
//FUNCTION USING USER INTERFACE
let userInfo = function(user: User) {
let info = "Hello, " + user.name + " Your Age is - " + user.age + " and Address is -"
+ user.address;
return info;
}
//USER INFO JSON OBJECT
let info = { name: "Anil", age: 30, address: "Noida, India." };
//RESULT
console.log(userInfo(info));