Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript Pick multiple keys

interface A{
  a:{
    name: string
  }
  b:{
    age: number
  }
}

type PickMultiple = ..... //todo

const child:PickMultiple<A,['a','b']> = {
   name: 'mike',
   age: 18
}

How can I extract multiple keys? it was same as Pick Child key

Ofcourse Pick<A, 'a'| 'b'> can't work as expected

like image 880
xipper Avatar asked Feb 17 '26 03:02

xipper


1 Answers

It already supports multiple keys

interface Todo {
  title: string;
  description: string;
  completed: boolean;
}
 
type TodoPreview = Pick<Todo, "title" | "completed">;
like image 66
Vladyslav Lazutkin Avatar answered Feb 18 '26 17:02

Vladyslav Lazutkin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!