Skip to content

objectCalls

Prefer {} object literal notation or Object.create instead of calling or constructing Object.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

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.

const
const emptyObject: Object
emptyObject
= new
var Object: ObjectConstructor
new (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: ObjectConstructor
new (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" });

This rule is not configurable.

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.

Made with ❤️‍🔥 around the world by the Flint team and contributors.