# vitest/prefer-to-be-object

> Require `toBeObject()` when `expectTypeOf()` checks for an object

`expectTypeOf()` has its own matcher for object types, `toBeObject()`. `toBeInstanceOf(Object)` and an `instanceof Object` check are longer ways to ask the same question.

The rule only checks `expectTypeOf()`. `expect(value).toBeInstanceOf(Object)` isn't reported.

`--fix` rewrites the assertion to `toBeObject()`, or to `.not.toBeObject()` if the original tested for the opposite.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"vitest/prefer-to-be-object" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 3} */}
```ts
import { expectTypeOf, test } from "vitest";

test("the config is an object", () => {
  const config = loadConfig();
  expectTypeOf(config).toBeInstanceOf(Object);
  expectTypeOf(config instanceof Object).toBeTruthy();
  expectTypeOf(config.name instanceof Object).toBeFalsy();
});
```

Not reported:

{/* good */}
```ts
import { expect, expectTypeOf, test } from "vitest";

test("the config is an object", () => {
  const config = loadConfig();
  expectTypeOf(config).toBeObject();
  expectTypeOf(config.name).not.toBeObject();
  expectTypeOf(config.createdAt).toBeInstanceOf(Date);
  expect(config).toBeInstanceOf(Object);
});
```
