Description
According to the documentation Null and Undefined are assignable to void
.
However, when using the
--strictNullChecks
flag,null
andundefined
are only assignable tovoid
and their respective types. This helps avoid many common errors. In cases where you want to pass in either astring
ornull
orundefined
, you can use the union typestring
|null
|undefined
. Once again, more on union types later on.
Bun in my experience only undefined
is actually assignable to void
:
TypeScript Version: 2.3
let thing: void = null; // <- Type 'null' is not assignable to type 'void'.
Expected behavior:
I would expect null
to be assignable to void
. It makes for void
to be just a union type void = null | undefined
otherwise it's just an alias for undefined
.
Actual behavior:
Only undefined
is assignable to void
.