0 of 6 problems solved0%
5 of 6

Get Deep Property

You can nest indexed access: T[K1][K2] looks up the type of a property inside another property. Constrain keys so each step is valid: K1 extends keyof T and K2 extends keyof T[K1].

function get<T, K extends keyof T>(o: T, k: K): T[K] {
  return o[k];
}

Now extend this pattern for two levels of depth.

Your Task

Read a nested property at two key levels.

  • Implement function getDeep<T, K1 extends keyof T, K2 extends keyof T[K1]>(obj: T, k1: K1, k2: K2): T[K1][K2].
  • Return obj[k1][k2].
  • Do not change the object; just read.