Void type

If your function does not return an explicit type, you will need to use void as your return type.

function logMessage(message: string): void {
  console.log(message);
}

void is the absence of having any type at all.

Declaring variables of type void is possible; however, it is not useful because you can only assign undefined or null to them:

const unusable: void = undefined; // Allowed, but useless
const unusable: void = []; // Error

Last updated