Skip to content

Instantly share code, notes, and snippets.

@KOBA789
Created June 27, 2017 14:08
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 KOBA789/7a12a810ca6763f518647f8fe290e596 to your computer and use it in GitHub Desktop.
Save KOBA789/7a12a810ca6763f518647f8fe290e596 to your computer and use it in GitHub Desktop.
function dig<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
const s: string = dig({ a: 'hoge', b: 1 }, 'a');
const t: number = dig({ a: 'hoge', b: 1 }, 'b');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment