Created
May 24, 2017 06:48
-
-
Save zhentian-wan/9f0d3d68bd441113bcd077a57f22f6d0 to your computer and use it in GitHub Desktop.
lookup types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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