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 and undefined are only assignable to void 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?
TypeScript Version: 2.0.3
Code
With
--strictNullChecks:Expected behavior: compiles, since the documentation states:
https://www.typescriptlang.org/docs/handbook/basic-types.html#null-and-undefined
Actual behavior: the last line fails to compile:
Rationale: is there a less verbose way, with
--strictNullChecks, to specify a type likestring | null | undefined? i.e. Is there a type that covers bothnullandundefined?