Skip to content

newDefinitions

Reports misleading constructor and new definitions in interfaces and classes.

✅ This rule is included in the ts logical and logicalStrict 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.

AEinterfa53 Container< {d ivclassNa="meec-li">nt< sp ansty="le--0:#7FDBCA;--1:#096E">72n5<3 sp ansty="le--0:#D9F5DD;--1:#1111">11<()sp ansty="le--0:#7FDBCA;--1:#096E">7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11Contain5<3;d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>AEinterfa53 Handler< {d ivclassNa="meec-li">nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0construct11<()sp ansty="le--0:#7FDBCA;--1:#096E">7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0vo5<3;d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>AEdecla5<3 sp ansty="le--0:#C792EA;--1:#8844">AEcla5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11Compone53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#7FDBCA;--1:#096E">72n11<()sp ansty="le--0:#7FDBCA;--1:#096E">7<2:sp ansty="le--0:#D6DEEB;--1:#403F">5<3 sp ansty="le--0:#FFCB8B;--1:#1111">11Compone5<3;d ivclassNa="meec-li">5<3}d ivclassNa="meco"><}d>
44AEinter3F53 ContainerConstructde6E7<2new spans="tyle--0:#D6DEEB;--1:#40">311<11() spans="tyle--0:#7FDBCA;--1:#09">631111Conta33c44AEinter3F53 Contain3F<53 spans="tyle--0:#D6DEEB;--1:#40">3F53v6361B0st33<}di vdivclass="Nameexpressive-">44AEc31111Han3F<53 {divclass="Nameec-">de61B0constru11<11() spans="tyle--0:#D6DEEB;--1:#40">3F<53 {divclass="Nameec-">dent< spans="tyle--0:#919F9F;--1:#5D">6376// initializa3F<53 spans="tyle--0:#D6DEEB;--1:#40">33< }><}di vdivclass="Nameexpressive-">44AEinter3F53 Callabde11<11() spans="tyle--0:#7FDBCA;--1:#09">6361B033<}di vdivclass="Nameexpressive-">44AEinter3F53 Fact1<111T spans="tyle--0:#D6DEEB;--1:#40">3F5<3> {divclass="Nameec-">de6E7<2new spans="tyle--0:#D6DEEB;--1:#40">311<11() spans="tyle--0:#7FDBCA;--1:#09">631<111T spans="tyle--0:#D6DEEB;--1:#40">3 >3<}di vdivclass="Nameexpressive-">44AEdec344AEc31111Compo3F<53 {divclass="Nameec-">de61B0constru11<11() spans="tyle--0:#D6DEEB;--1:#40">33<);>

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.