Skip to content

anyAssignments

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

✅ This rule is included in the ts logical and logicalStrict presets.

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
const value: any
value
=
const someFunction: () => unknown
someFunction
() as any;
const
const data: any
data
=
var Object: ObjectConstructor

Provides functionality common to all JavaScript objects.

Object
.
ObjectConstructor.create(o: object | null): any (+1 overload)

Creates an object that has the specified prototype or that has null prototype.

@paramo Object to use as a prototype. May be null.

create
(null);
const
const items: any[]
items
= [] as any[];
const [
const first: any
first
,
const second: any
second
] =
const getArray: () => unknown[]
getArray
() as any[];
const
const value: Set<string>
value
:
interface Set<T>
Set
<string> = new
var Set: SetConstructor
new <any>(iterable?: Iterable<any> | null | undefined) => Set<any> (+1 overload)
Set
<any>();
const
const items: string[]
items
: string[] = [...(
const getItems: () => unknown[]
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 ❤️‍🔥 around the world by the Flint team and contributors.