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 !?).

0

1 Answer 1

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"].

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.