anyReturns
Reports returning a value with type
anyfrom 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.
Examples
Section titled “Examples”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>();}function foo1() { return 1;}function foo2() { return [];}async function foo3() { return Promise.resolve({});}function assignability(): Set<string> { return new Set<string>();}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
@typescript-eslint/no-unsafe-return - Oxlint:
typescript/no-unsafe-return