Syntax
class Name implements InterfaceName { }Examples
Enforcing a Contract
A class guaranteed to match an interface's shape.
interface Printable {
print(): void;
}
interface Serializable {
serialize(): string;
}
class Document implements Printable, Serializable {
constructor(private content: string) {}
print(): void {
console.log(this.content);
}
serialize(): string {
return JSON.stringify({ content: this.content });
}
}
// If Document were missing either method, TypeScript would flag it immediatelyBest practices
- Use implements to guarantee a class provides all the members a given interface requires, catching missing implementations at compile time
- A class can implement multiple interfaces at once, comma-separated - useful for composing several small, focused contracts
- Remember implements provides no code - it is purely a type-level check; use extends when you actually want to inherit real behavior
- Combine implements with an interface exported from a shared location when multiple classes across a codebase need to honor the same contract
Runtime & versions
Compiled to JavaScript. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
TypeScript Handbook