Skip to content

Instantly share code, notes, and snippets.

@jeffmo
Last active May 11, 2016 17:49
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 jeffmo/ae22177b9c8df28a5b8a209ff805288b to your computer and use it in GitHub Desktop.
Save jeffmo/ae22177b9c8df28a5b8a209ff805288b to your computer and use it in GitHub Desktop.
var a: mixed = foo();
var b: number;
b = a; // error! `a` might not be a number... Could be anything!
if (typeof a === 'number')) {
b = a; // This is safe -- no error
} else {
throw new Error('Unexpected type of `a`!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment