• Error
  • Reported by the type checker

TS2355

A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.

A function declares a return type but has no `return` with a value. Return a value, or change the return type to `void`.

What it means

A function with a declared return type other than void, undefined, any or unknown must return a value. A body with no return statement at all is reported at the return type.

Example

index.ts
export function total(prices: number[]): number {
  prices.forEach(p => p);
}
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(1,42): error TS2355: A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.

Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.

How to fix

  • Return a value of the declared type.
  • If the function returns nothing, declare it as void.