absolute/explicit-object-types
Require explicit type annotations for object literals and arrays of object literals.
#Rule Details
Requires object literals (and arrays of object literals) assigned to a variable to carry an explicit type annotation rather than relying on inference. Naming the shape makes it reusable, surfaces it in editor tooltips, and turns a loose literal into a contract the rest of the codebase can depend on.
Only the outermost literal of a const/let declarator is checked. Destructuring patterns and declarations without an initializer are left alone, and as const is accepted because it already pins the object to a constant, fully-known shape.
#Examples
const user = { id: '1', name: 'Ada' }; // objectLiteralNeedsType
const rows = [{ id: 1 }, { id: 2 }]; // arrayOfObjectLiteralsNeedsType
const merged = [...others, { id: 3 }]; // arrayOfObjectLiteralsNeedsTypeAnnotated object and array
type Point = { x: number; y: number };
const origin: Point = { x: 0, y: 0 };
const items: MenuItem[] = [{ id: 'a' }, { id: 'b' }];const config = { mode: 'dark' } as const; // constant shape
const { x } = origin; // destructuring is not flagged
const count = 42; // non-object initializer#Configuration
Enable this rule in your ESLint configuration:
{
rules: {
'absolute/explicit-object-types': 'error'
}
}#Related Rules
#When Not To Use It
Local, throwaway objects that are never reused can make this rule feel noisy. If your project leans heavily on inference for one-off config objects, scope the rule to shared modules instead of enabling it everywhere.