Skip to content
Latchkey

TS2366: Function lacks ending return statement - in CI

A function declares a return type but a code path reaches the end without returning a value.

What this error means

Type-checking fails with TS2366 because not all branches return, yet the declared return type excludes undefined.

tsc
src/grade.ts(3,32): error TS2366: Function lacks ending return statement and return type does not include 'undefined'.

Common causes

How to fix it

Return on every path

  1. Add a final return or a default/exhaustive branch
ts
function grade(n: number): string {
  if (n >= 90) return "A"
  return "F"
}

Widen the return type if undefined is valid

  1. Declare the return type as T | undefined when some paths legitimately return nothing

How to prevent it

  • Keep noImplicitReturns on and make branching functions exhaustive or explicitly nullable.

Frequently asked questions

What causes "TS2366 missing return"?
Type-checking fails with TS2366 because not all branches return, yet the declared return type excludes undefined.
How do I fix TS2366 missing return?
Return on every path

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card