Loading...
type ElementOf<T> = T extends any[] ? any : never;
type X = ElementOf<string[]>;type ElementOf<T> = T extends (infer U)[] ? U : never;
type X = ElementOf<string[]>;infer U captures the array element type, so X is string instead of any.
infer appears only in the extends clause of a conditional type.ReturnType, Parameters and Awaited are used instead of hand-written infer copies.infer U extends string.No, infer is only allowed in the extends clause of a conditional type.
Wrap both sides in brackets: [T] extends [U] ? X : Y. The check then runs once on the whole union.