1

Let's say I have following type:

type TestType = { abc: string }[];

I would like to extract { abc: string } part, but don't know how.

I tried to get first element from tuple, but no luck:

type Head<T extends any[]> = T extends [a: infer A, ...args: any[]] ? A : never;

that approach works for [{ abc: string }] but not for { abc: string }[] although types are the same (I guess !?).

i474232898
  • 781
  • 14
  • 25

1 Answers1

0

Given type TestType = { abc: string }[];, you can do:

type ExtractedType = TestType[number]; which is equal to { abc: string }

Moreover, if you need to extract the type of the property abc, you could then do type Foo = ExtractedType["abc"].

Cr4zySheep
  • 81
  • 4