typescript / beginner
Snippet
The never Type
The never type represents values that never occur. It is used for functions that never return, such as those with infinite loops or those that always throw errors.
snippet.ts
1
2
3
4
5
function keepRunning(): never {while (true) {// Infinite loop}}
Breakdown
1
(): never
Specifies that the function will never reach a return statement.
2
while (true)
Creates a loop that continues indefinitely.