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
- 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
- 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
TS2366: Function lacks ending return statement - in CIFix "error TS2366: Function lacks ending return statement and return type does not include 'undefined'" in CI.
TS2322: Type is not assignable - in CIFix "error TS2322: Type 'X' is not assignable to type 'Y'" when tsc runs in CI - a genuine type mismatch on a…
TS6133: Declared but its value is never read - in CIFix "error TS6133: 'x' is declared but its value is never read" under noUnusedLocals/noUnusedParameters when…