Skip to content
Latchkey

TS7030: Not all code paths return a value - in CI

With noImplicitReturns enabled, some branch of a function returns a value while another implicitly returns undefined.

What this error means

Type-checking fails with TS7030 pointing at a function where one path returns and another does not.

tsc
src/pick.ts(2,29): error TS7030: Not all code paths return a value.

Common causes

How to fix it

Make every branch return

  1. Add returns to the missing branches or a trailing return
ts
function pick(x: number) {
  if (x > 0) return "pos"
  if (x < 0) return "neg"
  return "zero"
}

Return undefined explicitly

  1. If returning nothing is intended, return undefined and reflect it in the type

How to prevent it

  • Keep noImplicitReturns on so missing returns fail in CI rather than producing accidental undefined.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →