Common causes
- An if/else block that only has a return in the if branch, not the else
- A switch statement that doesn't cover all cases and is missing a default return
- noImplicitReturns: true or strict mode enabled
- An early return that handles one case, with the remaining code path missing a return
How to fix it
- Add a return statement to every code path that doesn't already have one
- Add a default return at the end of the function as a catch-all
- Include undefined in the return type if some paths intentionally return nothing: string | undefined
- Refactor the function to have a single clear return path
Example
function getLabel(code: number): string {
if (code === 1) { return 'one'; }
// error TS7030: Not all code paths return a value.
}Function with return type string but only returns in one branch — the default case is missing
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.
