Search⌘ K

Using the never type

Explore the never type in TypeScript and understand how it represents values that never occur. This lesson explains its role with examples like infinite loops and highlights its use for marking unreachable code, helping you write safer, more robust React applications.

We'll cover the following...

An example #

The code below is an arrow function expression that contains an infinite loop where a message is output to the console:

TypeScript 3.3.4
const keepLogging = (message: string) => {
while (true) {
console.log(message);
}
}

What do you think ...