Created
April 30, 2020 00:41
-
-
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
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
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