Skip to content

anyReturns

Reports returning a value with type any from a function.

✅ This rule is included in the ts logical preset.

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 foo1() {
return 1 as any;
}
function foo2() {
return [] as any[];
}
async function foo3() {
return Promise.resolve({} as any);
}
function assignability(): Set<string> {
return new 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 ❤️‍🔥 in Boston by Josh Goldberg and contributors.