Description
TypeScript Version: 2.0.3
Code
With --strictNullChecks
:
let x: string | void = 'hello';
let y: string | void = undefined;
let z: string | void = null;
Expected behavior: compiles, since the documentation states:
However, when using the
--strictNullChecks
flag,null
andundefined
are only assignable tovoid
and their respective types.
https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined
Actual behavior: the last line fails to compile:
[eval].ts (3,1): Type 'null' is not assignable to type 'string | void'. (2322)
Rationale: is there a less verbose way, with --strictNullChecks
, to specify a type like string | null | undefined
? i.e. Is there a type that covers both null
and undefined
?