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
- 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
- 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
TS7030: Not all code paths return a value - in CIFix "error TS7030: Not all code paths return a value" when tsc runs in CI under noImplicitReturns.
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…
TS2531: Object is possibly null - in CIFix "error TS2531: Object is possibly 'null'" when tsc runs in CI under strictNullChecks - guard the value be…