TypeScript
  • Introduction
  • Introduction
    • What is TypeScript?
    • Why TypeScript?
    • Setup
  • Beginner
    • Basic types
      • Primitive types
      • Arrays and tuples
      • Enums
      • Any type
    • Objects
    • Type aliases
    • Interfaces
    • Functions
      • Function signatures
      • Void type
      • Functions as types
    • Union types
    • Type guards
    • Intersection types
    • Nullable types
    • Inference
  • Resources
    • Resources
Powered by GitBook
On this page
  1. Beginner
  2. Functions

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
PreviousFunction signaturesNextFunctions as types

Last updated 6 years ago