Skip to content

newExpressions

Reports standalone new expressions that don't use the constructed object.

✅ This rule is included in the ts logical preset.

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.

// Constructing an object without using it
new MyClass();
function initialize() {
// Creating an instance but not capturing it
new EventEmitter();
}

This rule is not configurable.

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.

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