DEV Community

Discussion on: Understanding never in TypeScript

Collapse
 
totally_chase profile image
Phantz • Edited

In brief - In type theory, there's a clear distinction between a value that doesn't exist and a value that is of no importance. Usually, the former is known as Void and the latter is known as Unit.

Typescript is one of the few mainstream languages to have both concepts, Void in type theory, is never in typescript. And Unit in type theory, is (similar to) void in typescript, as well as other languages.

The nomenclature can be a bit confusing there. C decided to name the "value of no importance", void. And other languages followed suit. In reality void merely represents a value of no importance, rather than nothing at all. After all, if a function computes fully and returns to its parent - even if it has a return type of void, it did return. The value associated with said return was simply of no importance, therefore Unit. Meanwhile, saying a function returns Void (i.e never in typescript) is equivalent to saying it's impossible for the function to ever compute fully and return to the parent.