Implements
implements asks the compiler to check that a class's public instance shape matches one or more interfaces (or object types). It does not exist at runtime and it is not required for assignability.
Detailed Explanation
TypeScript is structural. A class that happens to have id: string and email: string is already a User as far as assignability is concerned. You do not need implements User for const u: User = new Person(...) to work.
What implements adds is an early, named check on the class. If Person is missing email, the error is on class Person implements User, not on some later assignment. That is why you write it: to pin a contract next to the implementation, and to have the compiler list the missing members when you change the interface.
You can implement more than one type: class C implements A, B. You can implement a type alias, not only an interface, as long as the alias is an object type with a static shape. You cannot implement a union. You cannot implement a primitive. You cannot implement a class's instance type in a way that pulls in its private members — those are not part of an interface.
implements checks the instance side. Static members are not part of the check. If the interface has a call signature, the class does not satisfy it by having a method of the same name; call signatures on an interface describe a function value, not a class. Construct signatures on an interface are similarly not what implements is for; they describe new.
Optional interface members may be omitted. readonly on the interface means the class should not expose a writable public field that contradicts it in some cases — the rules around readonly and methods are subtle, and a getter without a setter is the usual way to implement a readonly property.
A class may extend one class and implement several interfaces. implements does not call anything. There is no runtime registry of interfaces. instanceof User is a syntax error if User is an interface.
If you find yourself writing implements and then a pile of methods that only exist to satisfy the type, an object literal typed as the interface may be enough. implements earns its keep on classes that have real identity and behavior.
Code Examples
1. The check fires on the class.
// 1. The check fires on the class.
interface User {
id: string;
email: string;
}
class Person implements User {
constructor(public id: string, public email: string) {}
}
const u: User = new Person("u1", "ada@example.com");
console.log(u.email);2. Missing member — error at the class, not at the use site.
// 2. Missing member — error at the class, not at the use site.
interface Billable {
cents: number;
currency: string;
}
class Order implements Billable {
constructor(public cents: number) {}
// Error: Class 'Order' incorrectly implements interface 'Billable'.
// Property 'currency' is missing.
}3. Structural assignability works without implements.
// 3. Structural assignability works without implements.
class Legacy {
id = "u1";
email = "ada@example.com";
}
const also: User = new Legacy(); // fine — shape matchesCommon Gotchas
`implements` does not change emit and does not make `instanceof` work
it is a compile-time assertion about shape. Use a class or a brand if you need a runtime test.
You cannot `implement` a union or a primitive
split the union into two classes, or implement a shared object type.
Static members are not checked
an interface cannot require `static create()` via `implements`. Put a construct signature on a separate type and check `typeof Class`.
A wrong optional property type still fails
omitting `nickname?: string` is fine; implementing it as `nickname: number` is not.