newExpressions
Reports standalone new expressions that don't use the constructed object.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
Using the new keyword to construct an object without storing or using the result is often a mistake or indicates unclear code intent.
If a constructor has side effects that you want to trigger, it’s better to make those side effects explicit by calling a separate method rather than relying on constructor side effects.
Examples
Section titled “Examples”6376// Store the constructed ob44AEco44AEfuncdede3F <53 spans="tyle--0:#D6DEEB;--1:#40">3F53emi53 >36376// Return the constructed ob44AEfuncde36376// Throw an error ob44AEtOptions
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you have constructors that are intentionally designed to have side effects and you want to call them without using their return value, you might choose to disable this rule. However, in most cases, it’s better to refactor such code to make the side effects explicit through regular function calls rather than relying on constructor side effects.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noFloatingClasses - ESLint:
no-new - Oxlint:
eslint/no-newoxc/missing-throw
