1

I want to get the union of all they keys of my object recursively that is separated by period.

For example:

type User = {
    name: string;
    age: number;
    work: {
        company: string;
        position: string;
    }
}

I want to get 'name' | 'age' | 'work' | 'work.company' | 'work.position';

This is my initial code:

type RecursiveKeys<T> = T extends number | string | boolean ? T : {[K in keyof T]: `${K}.${RecursiveKeys<T[K]>}`}[keyof T]

I suspect my mistake is in this part of my code T extends number | string | boolean. I'm not sure what condition shall I put to end my recursive

Ryan Garde
  • 742
  • 1
  • 7
  • 20
  • 1
    See the answer to the linked question for more information. The solution looks like [this](https://tsplay.dev/mpnbgw) – jcalz Aug 01 '22 at 15:42
  • Its not perfect. It gives me this error `Type instantiation is excessively deep and possibly infinite.` – Ryan Garde Aug 01 '22 at 15:57

0 Answers0