-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
microsoft/TypeScript-Handbook
#1053Labels
DocsThe issue relates to how you learn TypeScriptThe issue relates to how you learn TypeScript
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
--strictNullChecksflag,nullandundefinedare only assignable tovoidand 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?
GoToLoop and karlhorky
Metadata
Metadata
Assignees
Labels
DocsThe issue relates to how you learn TypeScriptThe issue relates to how you learn TypeScript