Implementing Interfaces
A class can implement several interfaces and the compiler checks every member. Interfaces vanish at runtime.
Example
interface Printable { print(): string }
interface Savable { save(): boolean }
class Doc implements Printable, Savable {
print() { return "doc"; }
save() { return true; }
}
const d = new Doc();
console.log(d.print(), d.save());Result
doc true
Exercise
Promise an interface.
class D Printable
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.