Skip to content

Instantly share code, notes, and snippets.

@joshaber
Last active April 19, 2016 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshaber/9880c708157f42bbeec1f3afa9ea07e2 to your computer and use it in GitHub Desktop.
Save joshaber/9880c708157f42bbeec1f3afa9ea07e2 to your computer and use it in GitHub Desktop.
let thing: ?string = ... // `thing` is a nullable string
if (thing) {
// Within this `if`, `thing` is of type `string`. No longer nullable.
}
// Outside the `if`, `thing` is still a nullable string.
if (!thing) return
// Since we returned if `thing` is null, `thing` is now of type `string`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment