Why is TypeScript OK with an arrow function returning more than an explicit void, but errors on a function doing the same?

Viewed 93

I can't find an explanation for what happens in the following TypeScript snippet :

const f1: () => void = () => 4; // <- OK

function f2(): void {
  return 4; // <- Type 'number' is not assignable to type 'void'.
}

Playground link

Why is TypeScript OK with an arrow function returning more than an explicit void, but complains on a declared function doing the same ?

0 Answers
Related