typescript / beginner
Snippet
The 'never' Type
The 'never' type represents values that never occur. It is used for functions that always throw an error or contain infinite loops, meaning they never reach a return statement.
snippet.ts
1
2
3
function fail(message: string): never {throw new Error(message);}
Breakdown
1
: never
Indicates the function will never successfully finish or return a value.