November 2018
Beginner
502 pages
10h 22m
English
The never type represents something that would never occur and is typically used to specify unreachable areas of code. Again, this doesn't exist in JavaScript.
Time for an example:
function foreverTask(taskName: string): never { while (true) { console.log(`Doing ${taskName} over and over again ...`); }}
The function invokes an infinite loop and never returns, and so we have given it a type annotation of never. This is different to void because void means it will return, but with no value.
Read now
Unlock full access