Skip to content

Instantly share code, notes, and snippets.

@zhentian-wan
Created May 24, 2017 06:48
Show Gist options
  • Save zhentian-wan/9f0d3d68bd441113bcd077a57f22f6d0 to your computer and use it in GitHub Desktop.
Save zhentian-wan/9f0d3d68bd441113bcd077a57f22f6d0 to your computer and use it in GitHub Desktop.
lookup types
function spyOn<O extends object, P extends keyof O>(obj: O, prop: P) {
console.log(obj, prop);
}
interface IPerson {
name: string,
age: number
}
const person: IPerson = {
name: 'John',
age: 54
};
type keys = keyof IPerson;
spyOn(person, 'address'); // Catch error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment