typescript/consistent-return Suspicious
What it does
Enforce consistent return behavior in functions.
Why is this bad?
Mixing value-returning and non-value-returning code paths makes control flow harder to reason about and frequently indicates a bug.
WARNING
If possible, prefer TypeScript's noImplicitReturns compiler option over this rule. noImplicitReturns uses TypeScript's type information and control-flow analysis, so it can catch more implicit return paths than this rule.
Examples
Examples of incorrect code for this rule:
function maybe(flag: boolean): number {
if (flag) {
return 1;
}
return;
}Examples of correct code for this rule:
function maybe(flag: boolean): number {
if (flag) {
return 1;
}
return 0;
}Configuration
This rule accepts a configuration object with the following properties:
treatUndefinedAsUnspecified
type: boolean
default: false
Treat explicit return undefined as equivalent to an unspecified return.
How to use
To enable this rule using the config file or in the CLI, you can use:
{
"options": {
"typeAware": true
},
"rules": {
"typescript/consistent-return": "error"
}
}import { defineConfig } from "oxlint";
export default defineConfig({
options: { typeAware: true },
rules: {
"typescript/consistent-return": "error",
},
});oxlint --type-aware --deny typescript/consistent-returnVersion
This rule was added in v0.0.8.
