Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@azza85
Created April 30, 2020 00:41
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 azza85/aa13bcc17362d3a6aec1c0d8b537e2f6 to your computer and use it in GitHub Desktop.
Save azza85/aa13bcc17362d3a6aec1c0d8b537e2f6 to your computer and use it in GitHub Desktop.
Create a function where you pass in a key to object in typescript
type SubObjKey = keyof ISubObj;
type ObjKey = keyof IObj;
interface ISubObj {
subKey1: number;
subKey2: number;
}
interface IObj {
key1: ISubObj;
key2: ISubObj;
}
const myFunc = (data:IObj,key:ObjKey, subKey: SubObjKey) => data[key][subKey]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment