objectCalls
Prefer
{}object literal notation orObject.createinstead of calling or constructingObject.
✅ This rule is included in the ts stylistic preset.
Calling or constructing the global Object directly is unnecessarily verbose and less idiomatic than using object literal syntax.
Object literal notation {} is the preferred and more concise way to create plain objects in JavaScript and TypeScript.
Examples
Section titled “Examples”const emptyObject = new Object();const emptyObject = Object();const config = new Object({ key: "value" });const config = Object({ key: "value" });const emptyObject = {};const config = { key: "value" };const objectWithoutPrototype = Object.create(null);const copy = Object.assign({}, source);Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you have an existing codebase style that would be difficult to migrate away from, such as for consistency preferences with legacy code, you might find it difficult to onboard to this rule.
Alternately, if you target a legacy runtime with behavioral quirks where object literals behave differently than Object() calls, this rule might be counterproductive for you.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
no-object-constructor - Oxlint:
eslint/no-object-constructor
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.