Skip to main content

Functions & Return Types

TypeScript is not super happy that we have these things andthat they're not typed.So we're going to give those types here.

never

  • represents the type of values that never occur.
  • For example, never is the return type for a function expression or an arrow function expression that always throws an exception or one that never returns.
function error(message: string): never {
throw new Error(message);
}

void

  • The absence of having any type at all.
  • For example, declaring variables of type void is not useful because you can only assign undefined or null to them.
function log(message: string): void {
console.log(message);
}