how to make a type which only extracts property values from the interface in typescript?


I exactly don’t know how to express my intention in a single sentence, so I will try my best.

interface A {
  person: {
    name: string;
    age: number;
  count: number

type B = Pick<A, 'person'>

// type B = {person: {name: string; age: number;}}

As we can see, if we use Pick utility type, type B has a key person.

What if I want to get rid of the key(person), and only want to have those property values like below type C?

 // type C which I want to make.
 type C = {
   name: string;
   age: number;

 // something like StripKeyOut<Pick<A, 'person'>> is possible?

appreciate in advance for your help.

>Solution :

Typescript has Indexed Access Types: type B = A['person']


Leave a Reply Cancel reply