Common causes
- The return type is explicitly declared (e.g., string) but not all branches return that type
- An if-else chain missing the else branch return with an explicit return type
- A function that conditionally returns early but has no return for the default case
- Strict mode requiring all declared return types to be fully honoured on every path
How to fix it
- Add a return at the end of the function for the uncovered code path
- Change the return type to include undefined: string | undefined
- Restructure the function so every branch explicitly returns
- Add a throw to signal an impossible state: throw new Error('Unexpected state')
Example
function getStatus(code: number): string {
if (code === 200) return 'ok';
if (code === 404) return 'not found';
// error TS2366: Function lacks ending return statement and return type does not include 'undefined'.
}Return type is string but there's no catch-all return for unrecognized status codes
Browse more errors
The Developer Hub covers 150+ errors across Git, npm, Node.js, Python, TypeScript, and Docker — with plain-English explanations and fix steps.
