Skip to content

anyReturns

Reports returning a value with type any from a function.

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

Returning values typed as any in TypeScript effectively disables type checking and undermines the safety guarantees of the type system. This rule prevents functions from returning any, any[], or Promise<any>, as well as from returning generics that contain any in positions where a specific type is expected.

Prefer using more specific or unknown types to maintain strong type safety.

function
function foo1(): any
foo1
() {
return 1 as any;
}
function
function foo2(): any[]
foo2
() {
return [] as any[];
}
async function
function foo3(): Promise<any>
foo3
() {
return
var Promise: PromiseConstructor

Represents the completion of an asynchronous operation

Promise
.
PromiseConstructor.resolve<any>(value: any): Promise<any> (+2 overloads)

Creates a new resolved promise for the provided value.

@paramvalue A promise.

@returnsA promise whose internal state matches the provided promise.

resolve
({} as any);
}
function
function assignability(): Set<string>
assignability
():
interface Set<T>
Set
<string> {
return new
var Set: SetConstructor
new <any>(iterable?: Iterable<any> | null | undefined) => Set<any> (+1 overload)
Set
<any>();
}

This rule is not configurable.

If your codebase already contains many any types or areas of unsafe code, enabling this rule may be challenging. It may be more practical to defer enabling this rule until type safety has been improved in those areas. You might consider using Flint disable comments and/or configuration file disables for specific cases instead of completely disabling this rule.

Made with ❤️‍🔥 around the world by the Flint team and contributors.