Static Members
A static member belongs to the class constructor, not to an instance. You write static and call it as User.create(...). Its type lives on typeof User, not on User.
Detailed Explanation
An instance method needs a this that is an object you constructed. A static method does not. Factories, counters, and isUser(value)-style guards are the usual statics. Fields work the same way: static version = "1.0" is User.version, shared by the process, not per instance.
TypeScript types statics as properties of the constructor. typeof User has those members. The instance type User does not. user.create() is an error if create is static. User.create() is the call. This is the same split as Java or C#, and it is the same split as JavaScript's static keyword, which TypeScript is typing.
Statics can have visibility (private static cache), readonly, and generics on static methods (static from<T>(...)). They cannot access instance this. They can access other statics via the class name or this inside a static method, where this is the constructor type. Subclasses inherit statics through the constructor's prototype chain (class Admin extends User means Admin.create is User.create unless overridden). this in a static method of the parent may then refer to the subclass constructor, which is how a typed factory that returns InstanceType<typeof this> works.
implements does not look at statics. If you need to require a factory, type the constructor: type Ctor = { new (id: string): User; create(id: string): User }.
There is no static on interfaces. An interface describes an instance. A separate type describes the constructor.
abstract static methods exist in TypeScript: an abstract class can require subclasses to define a static. The check is a type check on the subclass constructor. Emit is still a missing property on the constructor function if you forget — which the compiler should have stopped.
Overuse of statics is a design smell (hidden global state, hard tests). A module-level function next to the class is often clearer and easier to tree-shake. Use statics when the operation is inherently about the class (User.parse, User.isUser) and you want it namespaced on User.
Code Examples
1. Instance type vs constructor type.
// 1. Instance type vs constructor type.
class User {
constructor(public id: string) {}
static create(id: string): User {
return new User(id);
}
label(): string {
return this.id;
}
}
const u = User.create("u1");
console.log(u.label()); // u1
// u.create("u2");
// Error: Property 'create' does not exist on type 'User'.2. A typed factory that uses the subclass constructor.
// 2. A typed factory that uses the subclass constructor.
class Row {
constructor(public id: string) {}
static build<T extends typeof Row>(this: T, id: string): InstanceType<T> {
return new this(id) as InstanceType<T>;
}
}
class AdminRow extends Row {
role = "admin" as const;
}
const admin = AdminRow.build("a1"); // AdminRow
console.log(admin.role);3. Requiring statics with a constructor type, not implements.
// 3. Requiring statics with a constructor type, not implements.
type Factory<T> = { new (id: string): T; create(id: string): T };
function make<T>(C: Factory<T>, id: string): T {
return C.create(id);
}
const made = make(User, "u2");Common Gotchas
Statics are not on the instance type
`implements` will not require them. Type `typeof Class` or write a constructor type.
Static mutable fields are process-wide state
tests will leak if you do not reset them. Prefer a function parameter or a small service object.
`this` in a static method is the constructor
`new this()` works when `this` is typed as a construct signature. Annotate `this: typeof Row` (or a generic subclass) so the return type is right.
`abstract static` is a TypeScript check only
the runtime constructor will not throw if some JS subclass omitted the static.