consistent-return
Added in v0.1.14Configuration
Rule Details
Require return statements to either always or never specify values. This is the TypeScript-enhanced version of the ESLint consistent-return rule. It uses type information to ignore bare return statements when a synchronous function has a return type containing void, or an async function returns a thenable whose resolved type contains void. This includes number | void and Promise<number | void>. A return type of undefined alone does not grant this exemption.
The first checked return determines whether later returns must specify a value. The rule reports each conflicting return statement and reachable function endings that omit a required value. With treatUndefinedAsUnspecified: true, undefined identifiers and void expressions count as unspecified values, as do expressions whose type is exactly undefined. A union type containing undefined does not by itself make an expression unspecified.
Examples of incorrect code for this rule:
Examples of correct code for this rule: