close

no-object-constructor

Unreleased

Configuration

rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-object-constructor': 'error',
    },
  },
]);

Rule Details

Use of the Object constructor to construct a new empty object is generally discouraged in favor of object literal notation because of conciseness and because the Object global may be redefined. The exception is when the Object constructor is used to intentionally wrap a specified value which is passed as an argument.

This rule disallows calling the Object constructor without an argument.

Examples of incorrect code for this rule:

Object();

new Object();

Examples of correct code for this rule:

Object("foo");

const obj = { a: 1, b: 2 };

const isObject = (value) => value === Object(value);

const createObject = (Object) => new Object();

Differences from ESLint

  • When the object constructor call is fixed onto a new line right after certain TypeScript-only constructs — a type alias (type T = Foo), an ambient or overload function declaration (declare function foo()), an import-equals declaration (import Foo = Bar), or an as/satisfies type cast — rslint's suggested fix inserts a leading ; that ESLint omits (e.g. type T = Foo\n;({}) instead of type T = Foo\n({})). The extra semicolon never changes the resulting code's behavior.

Original Documentation