newDefinitions
Reports misleading constructor and
newdefinitions in interfaces and classes.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
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:
-
Interface
new()returning the interface type: An interface withnew(): InterfaceNameis 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. -
Interface with
constructormethod: Interfaces should usenew()signatures to describe constructables, notconstructor()methods. Theconstructorkeyword is used in classes, not interfaces. -
Class with
newmethod returning the class type: A class method namednewthat returns the class type looks like a constructor definition, but classes useconstructorinstead.
Examples
Section titled “Examples”interface Container { new (): Container;}interface Handler { constructor(): void;}declare class Component { new(): Component;}interface ContainerConstructor { new (): Container;}
interface Container { value: string;}class Handler { constructor() { // initialization }}interface Callable { (): void;}interface Factory<T> { new (): T;}declare class Component { constructor();}When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noMisleadingInstantiator - Deno:
no-misused-new - ESLint:
@typescript-eslint/no-misused-new - Oxlint:
typescript/no-misused-new