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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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 asUnit
.Typescript is one of the few mainstream languages to have both concepts,
Void
in type theory, isnever
in typescript. AndUnit
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 realityvoid
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 ofvoid
, it did return. The value associated with said return was simply of no importance, thereforeUnit
. Meanwhile, saying a function returnsVoid
(i.enever
in typescript) is equivalent to saying it's impossible for the function to ever compute fully and return to the parent.