no-unsafe-return
Disallow returning a value with type
anyfrom a function.
Extending "plugin:@typescript-eslint/recommended-type-checked" in an ESLint configuration enables this rule.
This rule requires type information to run.
The any type in TypeScript is a dangerous "escape hatch" from the type system.
Using any disables many type checking rules and is generally best used only as a last resort or when prototyping code.
Despite your best intentions, the any type can sometimes leak into your codebase.
Returning an any-typed value from a function creates a potential type safety hole and source of bugs in your codebase.
This rule disallows returning any or any[] from a function and returning Promise<any> from an async function.
This rule also compares generic type argument types to ensure you don't return an unsafe any in a generic position to a function that's expecting a specific type.
For example, it will error if you return Set<any> from a function declared as returning Set<string>.
- Flat Config
- Legacy Config
export default tseslint.config({
rules: {
"@typescript-eslint/no-unsafe-return": "error"
}
});
module.exports = {
"rules": {
"@typescript-eslint/no-unsafe-return": "error"
}
};
Try this rule in the playground ↗
Examples
- ❌ Incorrect