Skip to content

Instantly share code, notes, and snippets.

@asiniy
Created July 4, 2018 11:23
Show Gist options
  • Save asiniy/224944352d32672fb5d520ea77a3ec7b to your computer and use it in GitHub Desktop.
Save asiniy/224944352d32672fb5d520ea77a3ec7b to your computer and use it in GitHub Desktop.
index.js // Extending JavaScript with ease (beginner level tutorial)
// The only significant difference between TS and JavaScript is interface.
// Interface declarates that object passed as `obj` should be an object actually
interface PassedObject {
readonly [key: string]: any;
}
// Same logic as in our ES6 code
const objectFetch = (obj: PassedObject, property: string): any => {
// tslint:disable-next-line:no-if-statement
if (obj.hasOwnProperty(property)) {
return obj[property];
}
throw new ReferenceError(`No such property: ${property}`);
};
export default objectFetch;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment