Home > Back-end >  How to Pick a type from a nested array type?
How to Pick a type from a nested array type?

Time:01-16

I am trying to Pick a type from another type which is a nested array.

Example Extract the Fighter (singular) type from the Card type:

type Card = {
    id: number;
    name: string;
    fights: (Fight & {
        fighters: Fighter[];
    })[];
}

If I do the following I get the Fights (Fight array type)

type Fights = Pick<Card, 'fights'>

How can I Pick the Fighter type?

CodePudding user response:

type FighterType = Card['fights'][0]['fighters'][0];
  •  Tags:  
  • Related