According to this answer:
Using
void
instead means that forEach promises not to use the return value, so it can be called with a callback that returns any value
According to the TypeScript 3.0 release notes
...
unknown
is the type-safe counterpart ofany
. Anything is assignable tounknown
, butunknown
isn’t assignable to anything but itself andany
...
As much as I think about this, from these descriptions I can't find any single difference between those types.
I have also noticed that unlike unknown
, when void
is used as a type of a function argument, that argument can be omitted when calling the function, even though it is not marked as optional:
declare const x: (a: void) => void
x()
While this behaviour is sometimes useful when working with generic code, it seems very strange. If void
is supposed to only ever be used in return types, why does it have this special behaviour, unlike every other type?