Last active
          February 22, 2019 20:38 
        
      - 
      
 - 
        
Save heikkipesonen/8808f0f20a3c57e0f2e5fd21e01b52d6 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
heikkipesonen revised this gist
Feb 22, 2019 . No changes.There are no files selected for viewing
 - 
        
heikkipesonen created this gist
Feb 22, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ type KeyOf<T> = keyof T function get<T, K1 extends KeyOf<T>>(o: T, p1: K1): T[K1] function get<T, K1 extends KeyOf<T>, K2 extends KeyOf<T[K1]>>(o: T, p1: K1, p2: K2): T[K1][K2] function get<T, K1 extends KeyOf<T>, K2 extends KeyOf<T[K1]>, K3 extends KeyOf<T[K1][K2]>>(o: T, p1: K1, p2: K2, p3: K3): T[K1][K2][K3] function get<T, K1 extends KeyOf<T>, K2 extends KeyOf<T[K1]>, K3 extends KeyOf<T[K1][K2]>, K4 extends KeyOf<T[K1][K2][K3]>>(o: T, p1: K1, p2: K2, p3: K3, p4: K4): T[K1][K2][K3][K4] function get<T, K1 extends KeyOf<T>, K2 extends KeyOf<T[K1]>, K3 extends KeyOf<T[K1][K2]>, K4 extends KeyOf<T[K1][K2][K3]>, K5 extends KeyOf<T[K1][K2][K3][K4]>>(o: T, p1: K1, p2: K2, p3: K3, p4: K4, p5: K5): T[K1][K2][K3][K4][K5] function get<T, K1 extends KeyOf<T>, K2 extends KeyOf<T[K1]>, K3 extends KeyOf<T[K1][K2]>, K4 extends KeyOf<T[K1][K2][K3]>, K5 extends KeyOf<T[K1][K2][K3][K4]>>(o: T, p1: K1, p2?: K2, p3?: K3, p4?: K4, p5?: K5) { return p5 && p4 && p3 && p2 ? o[p1][p2][p3][p4][p5] : p4 && p3 && p2 ? o[p1][p2][p3][p4] : p3 && p2 ? o[p1][p2][p3] : p2 ? o[p1][p2] : o[p1] }