W
W
WbICHA2020-07-19 20:45:04
typescript
WbICHA, 2020-07-19 20:45:04

How to get the data type of an array in the interface, but not as an array?

The question was asked very badly, but it was not possible to formulate it better.
So I'll explain better with an example. There is an interface:

IQuery<IGroup>
IQuery<IGroup[]>

export type IQuery<T extends SomeType | SomeType[]> = 
  OtherType<T, T extends SomeType[] ? T[0] : T, {}>;

In this form, it does not work, but the logic of work should be like this. That is, I need the second OtherType argument to take T, but not as an array, and the first argument must be an array if T is an array.

Actually, is it possible to solve this problem at all, or will we have to make a second interface for arrays?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question