---
url: /docs/guide/usage/linter/rules/typescript/no-empty-object-type.md
---

### What it does

To avoid confusion around the `{}` type allowing any non-nullish value, this rule bans usage of the `{}` type. That includes interfaces and object type aliases with no fields.

### Why is this bad?

The `{}`, or "empty object" type in TypeScript is a common source of confusion for developers unfamiliar with TypeScript's structural typing. `{}` represents any non-nullish value, including literals like 0 and "".
Often, developers writing `{}` actually mean either:

* object: representing any object value
* unknown: representing any value at all, including `null` and `undefined`
  In other words, the "empty object" type {}\` really means "any value that is defined". That includes arrays, class instances, functions, and primitives such as string and symbol.

Note that this rule does not report on:

* `{}` as a type constituent in an intersection type (e.g. types like TypeScript's built-in `type NonNullable<T> = T & {}`), as this can be useful in type system operations.
* Interfaces that extend from multiple other interfaces.

### Examples

Examples of **incorrect** code for this rule:

```ts
let anyObject: {};
let anyValue: {};
interface AnyObjectA {}
interface AnyValueA {}
type AnyObjectB = {};
type AnyValueB = {};
```

Examples of **correct** code for this rule:

```ts
let anyObject: object;
let anyValue: unknown;
type AnyObjectA = object;
type AnyValueA = unknown;
type AnyObjectB = object;
type AnyValueB = unknown;
let objectWith: { property: boolean };
interface InterfaceWith {
  property: boolean;
}
type TypeWith = { property: boolean };
```

## Configuration

This rule accepts a configuration object with the following properties:

### allowInterfaces

type: `"never" | "always" | "with-single-extends"`

default: `"never"`

Whether to allow empty interfaces.

#### `"never"`

Never allow interfaces with no fields.

#### `"always"`

Always allow interfaces with no fields.

#### `"with-single-extends"`

Allow empty interfaces that `extend` from a single base interface.

Examples of **correct** code for this rule with `{ allowInterfaces: 'with-single-extends' }`:

```ts
interface Base {
  value: boolean;
}
interface Derived extends Base {}
```

### allowObjectTypes

type: `"never" | "always"`

default: `"never"`

Whether to allow empty object type literals.

#### `"never"`

Never allow object type literals with no fields.

#### `"always"`

Always allow object type literals with no fields.

### allowWithName

type: `string`

A stringified regular expression to allow interfaces and object type aliases with the configured name.

This can be useful if your existing code style includes a pattern of declaring empty types with `{}` instead of `object`.

Example of **incorrect** code for this rule with `{ allowWithName: 'Props$' }`:

```ts
interface InterfaceValue {}
type TypeValue = {};
```

Example of **correct** code for this rule with `{ allowWithName: 'Props$' }`:

```ts
interface InterfaceProps {}
type TypeProps = {};
```

## How to use

## Version

This rule was added in v0.12.0.

## References
