Skip to content

consistent-type-definitions

JavaScript / TypeScriptstyleno fixdefault: off

Reports a type alias of an object type (type T = { a: 1 }, also {} and an index signature type). A union, an intersection or any other type in an alias is not reported.

An interface and an object type alias describe the same shape, but interfaces can be extended and merged, and the compiler reports their errors with the name of the interface instead of the expanded type. One form in a code base is easier to search.

To fix, write interface T { a: 1 }.

Reported
...
type A = {};
type B = {} & { a: 1 };
...
interface E extends A, B {}
interface F { a: 1 }
type L = { a: 1 };
type M = A | B;
...
js:
lint:
rules:
consistent-type-definitions: warn # off (default), warn, error

Suppress one line with sudsy-disable-next-line consistent-type-definitions in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
typescript-eslint consistent-type-definitions partial only the default interface style