ProjectStack
typescript

TS7030: Not all code paths return a value

Your function has branches where it might exit without returning a value, but the function's return type suggests it always returns something. TypeScript found a code path that falls off the end of the function without a return statement.

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

  1. Add a return statement to every code path that doesn't already have one
  2. Add a default return at the end of the function as a catch-all
  3. Include undefined in the return type if some paths intentionally return nothing: string | undefined
  4. 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.