Skip to content

Instantly share code, notes, and snippets.

@pietro909
Last active October 28, 2016 08:33
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 pietro909/9b39c109023c9c991f88a191b048f9bc to your computer and use it in GitHub Desktop.
Save pietro909/9b39c109023c9c991f88a191b048f9bc to your computer and use it in GitHub Desktop.
A runtime error in Typescript
function contains(c: string, arr: string) {
var index = arr.indexOf(c);
return index > -1;
}
console.clear();
console.log(contains("hi", "there")); // false
console.log(contains("hi", "hi, all")); // true
console.log(contains("hi", 1)); // doesn't compile
console.log(contains("hi", null)); // TypeError: Cannot read property 'indexOf' of null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment