Skip to content

anyAssignments

Reports assigning a value with type any to variables and properties.

✅ This rule is included in the ts logical preset.

The any type in TypeScript is a dangerous “escape hatch” from the type system. Assigning an any typed value to a variable can defeat TypeScript’s type safety guarantees, allowing unexpected types to propagate through your codebase.

This rule reports assigning any to a variable, destructuring from any[], and spreading any[] into typed arrays. It also checks generic type arguments to ensure you don’t pass an unsafe any in a generic position.

const value = someFunction() as any;
const data = Object.create(null);
const items = [] as any[];
const [first, second] = getArray() as any[];
const value: Set<string> = new Set<any>();
const items: string[] = [...(getItems() as any[])];

This rule is not configurable.

If your codebase has many existing any types or areas of unsafe code, it may be difficult to enable this rule. You might consider using lint disable comments for specific situations instead of completely disabling this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.