consistent-type-definitions
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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 }.
Example
Section titled “Example”...type A = {};type B = {} & { a: 1 };...interface E extends A, B {}interface F { a: 1 }type L = { a: 1 };type M = A | B;...Configuration
Section titled “Configuration”js: lint: rules: consistent-type-definitions: warn # off (default), warn, errorSuppress one line with sudsy-disable-next-line consistent-type-definitions in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”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 |