DEV Community

Discussion on: TypeScript Utility: keyof nested object

Collapse
 
dzey profile image
Jakub Królak

I found this solution that I think is simpler and easier to understand

type NestedKeyOf<T, K = keyof T> = K extends keyof T & (string | number)
  ? `${K}` | (T[K] extends object ? `${K}.${NestedKeyOf<T[K]>}` : never)
  : never
Enter fullscreen mode Exit fullscreen mode