objectCalls
Prefer
{}object literal notation orObject.createinstead of calling or constructingObject.
✅ This rule is included in the tsstylisticandstylisticStrictpresets.
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 const emptyObject: Object
emptyObject = new var Object: ObjectConstructornew (value?: any) => Object
Provides functionality common to all JavaScript objects.
Object();const const emptyObject: any
emptyObject = var Object: ObjectConstructor() => any (+1 overload)
Object();const const config: Object
config = new var Object: ObjectConstructornew (value?: any) => Object
Provides functionality common to all JavaScript objects.
Object({ key: string
key: "value" });const const config: any
config = var Object: ObjectConstructor(value: any) => any (+1 overload)
Object({ key: string
key: "value" });const const emptyObject: {}
emptyObject = {};const const config: { key: string;}
config = { key: string
key: "value" };const const objectWithoutPrototype: any
objectWithoutPrototype = var Object: ObjectConstructor
Provides functionality common to all JavaScript objects.
Object.ObjectConstructor.create(o: object | null): any (+1 overload)
Creates an object that has the specified prototype or that has null prototype.
create(null);const const copy: any
copy = var Object: ObjectConstructor
Provides functionality common to all JavaScript objects.
Object.ObjectConstructor.assign<{}, any>(target: {}, source: any): any (+3 overloads)
Copy the values of all of the enumerable own properties from one or more source objects to a
target object. Returns the target object.
assign({}, const source: any
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