@typescript-eslint/no-generated-empty-object-type
Disallow type operations that produce the {} type
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.
[lint.rules]
"@typescript-eslint/no-generated-empty-object-type" = "error" # or "warn"Examples#
type User = { name: string };
type Rest = Omit<User, "name">This type resolves to {}, the empty object type. This was likely not intentional.;
const rest: Rest = 42; // no type errortype User = { name: string };
type Value = NonNullable<unknown>This type resolves to {}, the empty object type. This was likely not intentional.;
type Rest = Omit<User, "name"> & {}This type resolves to {}, the empty object type. This was likely not intentional.;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:
function update<T extends object, K extends keyof T>(target: T, rest: Omit<T, K>) {
Object.assign(target, rest);
}