What it is and why to use it
noImplicitReturns checks functions for inconsistent return paths. It is useful when refactoring branches could accidentally leave some inputs returning undefined. Combined with explicit return types, it encourages a function to explain the result of every intended path.
Common mistakes and limitations
This is not a requirement that every procedure return a value; a consistently void function is valid. A function that always throws also has no normal return. Choose an explicit return type when missing values would violate the contract.
Run this example
Use TypeScript 5.8 or later with strict checking and an ES2022 target. Save each complete example independently as example.ts, compile it, then run the generated JavaScript with a compatible Node.js installation. Compiler-only options below affect checking; they do not add runtime validation.
Terminal — compile and run
npx tsc example.ts --strict --target ES2022 --module commonjs
node example.jsSyntax
"noImplicitReturns": trueExamples
Checking Return Paths with noImplicitReturns
Standalone TypeScript 5.8+ example; expected output is explained below.
function status(score: number): string {
if (score >= 50) return "Pass";
return "Try again";
}
console.log(status(72));
console.log(status(40));- The first branch returns Pass when the threshold is met.
- The final return covers every remaining number.
- Compile with --noImplicitReturns to check this policy explicitly. The option is separate from strict and does not insert a return statement into emitted JavaScript.
- Expected output: Pass Try again
Best practices
- This is not a requirement that every procedure return a value; a consistently void function is valid. A function that always throws also has no normal return. Choose an explicit return type when missing values would violate the contract.
- Keep external-input validation separate from compile-time type descriptions.
Runtime & versions
Compiled to JavaScript. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
TypeScript Handbook