Skip to content

Instantly share code, notes, and snippets.

@joanllenas
Created March 4, 2017 22:55
Show Gist options
  • Save joanllenas/d74f14a7418d0b037548d300f0c224c6 to your computer and use it in GitHub Desktop.
Save joanllenas/d74f14a7418d0b037548d300f0c224c6 to your computer and use it in GitHub Desktop.
TS nullable types
// The compiler has the --strictNullChecks flag set
let cannotBeNull = "I can't be null nor undefined";
cannotBeNull = null; // error, 'null' is not assignable to 'string'
cannotBeNull = undefined; // error, 'undefined' is not assignable to 'string'
let nullable: string | null = "I can be null but not undefined";
nullable = null;
nullable = undefined; // error, 'undefined' is not assignable to 'string | null'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment