@typescript-eslint/no-generated-empty-object-type

Disallow type operations that produce the {} type

needs types

Also called typescript-eslint/no-generated-empty-object-type, typescript/no-generated-empty-object-type

Omit, Pick, NonNullable and other type helpers can resolve to {}. That type accepts every value except null and undefined, so 0 and "" pass. The type looks like it describes an object, but it checks almost nothing.

Check the keys you pass to the helper. For an object with no properties, write Record<string, never>.

The rule looks at generic types with type arguments and at intersections. A {} that you write yourself is reported by @typescript-eslint/no-empty-object-type, not by this rule.

Configure#

Off by default. This rule needs types, so turning it on makes bun lint type check your code first.

bunfig.toml
[lint.rules]
"@typescript-eslint/no-generated-empty-object-type" = "error" # or "warn"

Examples#

example.ts1 problem
type User = { name: string };

type Rest = Omit<User, "name">;

const rest: Rest = 42; // no type error
example.ts2 problems
type User = { name: string };

type Value = NonNullable<unknown>;
type Rest = Omit<User, "name"> & {};
example.tsNo problems
type User = { name: string; email: string };

type Contact = Omit<User, "name">;
type NoFields = Record<string, never>;
type Empty = {};

A type that depends on a type parameter isn't reported, because the result isn't known yet:

example.tsNo problems
function update<T extends object, K extends keyof T>(target: T, rest: Omit<T, K>) {
  Object.assign(target, rest);
}