Implementing Interfaces with Classes
Enforce class structure with the implements keyword.
Welcome
The `implements` keyword ensures a class fulfills an interface contract. TypeScript verifies the class provides all required properties and methods.
Basic implements
Use `implements InterfaceName` after the class name. TypeScript errors if any required member is missing.
interface Printable {
print(): void;
}
class Document implements Printable {
print() { console.log('Printing...'); }
}All lessons in this course
- TypeScript Classes and Constructors
- public, private, and protected Modifiers
- readonly Properties and Parameter Properties
- Implementing Interfaces with Classes