Skip to main content

TypeScript Interface

TypeScript interface can define both property and method.

Example

interface Contact {
name: string;
age: number;

getWorkPhone(): string;

getHomePhone: () => string;
}

class Person implements Contact {
name: string;
age: number;

constructor(name: string, age: number) {
this.name = name;
this.age = age;
}

getWorkPhone(): string {
return '123-456-7890';
}

getHomePhone = (): string => {
return '098-765-4321';
}
}

References