Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

@typescript-eslint/consistent-type-definitions

Require either interface or type for object types, consistently

You can declare an object's shape with interface User { ... } or with type User = { ... }. For most code the two work the same. This rule picks one. By default it's interface.

The rule only reports a type that's an object type. You can't write unions, functions, and other types as an interface.

--fix rewrites the declaration to the other form.

Configure

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"@typescript-eslint/consistent-type-definitions" = "error" # or "warn"

Every option, set to its default:

bunfig.toml
[lint.rules]
# "interface" or "type"
"@typescript-eslint/consistent-type-definitions" = ["error", "interface"]

Examples

Reported:

type User = {
  name: string;
  email: string;
};

Not reported:

interface User {
  name: string;
  email: string;
}

type Id = string | number;
type Handler = (user: User) => void;

Options

OptionWhat it does
"interface" (default)Report type User = { ... }.
"type"Report every interface.
interface User {
  name: string;
}
type User = {
  name: string;
};

When not to use it

The two differ in a few ways. Two interface declarations with the same name merge, which is how you add to a global type such as Window. You can pass a type where a Record<string, unknown> is expected, but not an interface. If your code depends on both, leave this rule off.