A
A
Alexey Shashenkov2022-03-25 22:17:19
typescript
Alexey Shashenkov, 2022-03-25 22:17:19

How to access nested properties of a type using keyof?

I have a user type (example)
How can I convert it to userTarget type using generics?
The goal is to raise the keys to the first level from level 2. You don't need to go deeper.

type user = {
  user: {
    find: string;
    update: number;
  };
  account: {
    find: boolean;
    update: number;
  };
};

type userTarget = {
  user_find: string;
  user_update: number;
  account_find: boolean;
  account_update: number;
};

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question