Created
March 4, 2017 22:55
-
-
Save joanllenas/d74f14a7418d0b037548d300f0c224c6 to your computer and use it in GitHub Desktop.
TS nullable types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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