yaquawa
yaquawa

Reputation: 7338

Can I extract type from array?

Here is my goal, I'm wondering is it possible to create a PickFromArray type like this?

type FooBar = { foo: string, bar: number, foobar: string }
type Result = PickFromArray<FooBar,['foo','foobar']> // {foo: string, foobar: string}

Upvotes: 1

Views: 51

Answers (1)

yaquawa
yaquawa

Reputation: 7338

Solved.

type PickFromArray<T,U extends any[]> = Pick<T, U[number]>

Upvotes: 1

Related Questions