How to fix Type 'this' is not a class type in TypeScript

TypeScriptINTERMEDIATEMEDIUMUpdated Dec 11, 2025· 103 views

You get this error when TypeScript expects a constructor or class reference, but the polymorphic `this` instance type is supplied instead.

Quick fix

Fixes TS2509

type Constructor<T = {}> = new (...args: any[]) => T;

function Timestamped<TBase extends Constructor>(Base: TBase) {
  return class extends Base {
    timestamp = new Date();
  };
}
  1. Capture constructor types explicitly for mixins
  2. Use `typeof this` in static helpers
  3. Keep instance `this` inside members
typescript — error
type Constructor<T = {}> = new (...args: any[]) => T;
function Timestamped<TBase extends Constructor>(Base: TBase) {
return class extends Base {
timestamp = new Date();
};
}
Type 'this' is not a class type

What this error means

The special `this` type always refers to an instance, but `extends`, `new`, and constructor constraints require a class, constructor signature, or `typeof` reference. When a mixin or helper tries to reuse the instance-side `this` in those positions—such as `class Derived extends this`, `new this()`, or `T extends this`—the compiler raises TS2509 because `this` cannot stand for the constructor side of the class.

Typical symptoms

  • A compiler error TS2509 points at an `extends`, `new`, or constraint clause that mentions `this`.
  • Code that treats the current class as a constructor or mixin target stops compiling.
  • Linting or IntelliSense highlights the same `this` reference in the static context.
  • Trying to instantiate `this` or constrain a generic with `this` fails even though the same class works elsewhere.

Common causes

  1. Using the instance-type `this` where TypeScript expects the static constructor side (e.g., in `extends` or a `new` signature).
  2. Copying mixin scaffolding but forgetting to pass the constructor type or `typeof this` instead of the instance.
  3. Declaring a generic constraint such as `T extends this` inside a class or interface instead of using `typeof this` or an explicit constructor signature.
  4. Confusing `this` with `typeof this` when a static method wants to refer to the current class's constructor.

How to fix "Type 'this' is not a class type"

1Capture constructor types explicitly for mixins

Create a reusable constructor alias and use it to constrain the base class rather than the instance this:

ts
type Constructor<T = {}> = new (...args: any[]) => T;

function Timestamped<TBase extends Constructor>(Base: TBase) {
  return class extends Base {
    timestamp = new Date();
  };
}

This keeps TBase on the constructor side, so the mixin never mentions the instance this in a place that expects a class type.

2Use `typeof this` in static helpers

Static methods can see the constructor by typing this as T extends typeof Base:

ts
class Base {
  static make<T extends typeof Base>(this: T) {
    return new this();
  }
}

Here this is still polymorphic, but the constraint T extends typeof Base keeps the compiler on the constructor side and avoids TS2509.

3Keep instance `this` inside members

Reserve the instance this for methods, accessors, or this parameters so the compiler always knows it describes the subtype:

ts
class Fluent {
  setName(this: this, name: string) {
    return Object.assign(this, { name });
  }
}

Do not try to reuse that same this type for extends, implements, or new clauses; those positions need constructor-like types instead.

Advanced notes

Every class in TypeScript has two faces: the instance shape that flows through this, and the static constructor shape that appears in extends, implements, and new expressions. TS2509 is the compiler's way of reminding you that the instance this can only be used where the compiler already knows it is dealing with an instance; otherwise you must lift the type to typeof this or an explicit constructor signature. Mixins, factory helpers, and new expressions almost always belong to the static side, so anchor their generics to constructors instead of the polymorphic instance type.

Frequently asked questions

What does "TS2509" mean?
The special this type always refers to an instance, but extends, new, and constructor constraints require a class, constructor signature, or typeof reference. When a mixin or helper tries to reuse the instance-side this in those positions—such as class Derived extends this, new this(), or T extends this—the compiler raises TS2509 because this cannot stand for the constructor side of the class.
How do I fix "TS2509"?
You get this error when TypeScript expects a constructor or class reference, but the polymorphic this instance type is supplied instead.
What causes "TS2509"?
Using the instance-type this where TypeScript expects the static constructor side (e.g., in extends or a new signature). Copying mixin scaffolding but forgetting to pass the constructor type or typeof this instead of the instance. Declaring a generic constraint such as T extends this inside a class or interface instead of using typeof this or an explicit constructor signature.
Is the "TS2509" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading