Skip to content

newDefinitions

Reports misleading constructor and new definitions in interfaces and classes.

✅ This rule is included in the ts logical presets.

In TypeScript, classes and interfaces have different ways of defining how instances are created. This rule flags misleading definitions that confuse interface construct signatures with class constructors.

There are two common mistakes this rule catches:

  1. Interface new() returning the interface type: An interface with new(): InterfaceName is misleading because interfaces cannot be instantiated directly. If the interface describes a constructor function, the return type should typically be different from the interface name.

  2. Interface with constructor method: Interfaces should use new() signatures to describe constructables, not constructor() methods. The constructor keyword is used in classes, not interfaces.

  3. Class with new method returning the class type: A class method named new that returns the class type looks like a constructor definition, but classes use constructor instead.

interface Container {
new (): Container;
}
interface Handler {
constructor(): void;
}
declare class Component {
new(): Component;
}

This rule is useful for catching common mistakes when defining constructor-like signatures. If you have intentional advanced type patterns that this rule incorrectly flags, you may need to disable it.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.