Search⌘ K
AI Features

The Primitive Type never

Discover how the primitive never type in TypeScript represents code paths that never occur, such as exceptions or infinite loops. Learn how it aids exhaustive checks and enforces type safety by preventing unintended returns or unhandled cases in your programs.

We'll cover the following...

The type never means that nothing occurs. It is used when a type guard cannot occur or in a situation where an exception is always thrown. There is a difference between void and never. A function that has the explicit return type of never won’t allow your code to return undefined, which is different from a void function that allows code to return undefined.

TypeScript 3.3.4
function functionThrow(): never {
throw new Error("This function return never");
}

The never type is a subtype for every type. ...