Consider this example:
export async function foo(): Promise<string>{
await bar()
return;
}
No errors are thrown during compilation.
However, if you change the code to:
export async function foo(): Promise<string>{
await bar()
}
You will encounter an error. The specific error message is:
A function whose declared type is neither 'void' nor 'any' must return a value
So why does this happen?
It seems to be related to https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#63-function-implementations, as well as the complexity introduced by using async functions and TypeScript typing.
UPDATE:
For your information, having return;
, return
, or even return undefined;
in a function implies the same semantics perspective, correct?