Interface adalah suatu cara yang digunakan untuk object atau class 👉🏻 Lebih jelasnya langsung ke contohnya:
// profile -> name, address, age
interface profile {
name: string;
address: string;
age: number;
}
merge adalah jika ada 2 interface yang sama akan otomatis digabung. sebagai contoh:
// ada 2 interface yang sama
interface animals {
species: string;
}
interface animals {
name: string;
}
const myAnimal: animals = {
species: "persia"
name: "cat"
}
implements yaitu blue print dari class.
sebagai contoh:
interface User { // 👈🏻 blue print
firstName: string;
lastName: string;
address: string;
statues: string;
getName(id: number): string; // 👈🏻 method
}
class Profile implements User {
firstName: string;
lastName: string;
age: number;
address: string;
statues: string;
constructor(firstName: string, lastName: string, age: number, address: string, statues: string) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.address = address;
this.statues = statues;
}
getName(id: number) {
return 'Ok';
}
}