We've found this type handy in our codebase and thought this would be useful in type-fest too.
Proposal
ArrayItem extracts the type of the item(s) in the array:
type ArrayItem<TArray extends any[]> = TArray extends (infer E)[] ? E : TArray;
Possibly could be improved by replacing the fallback conditional with unknown instead of TArray.
playground example: https://www.typescriptlang.org/play/#code/C4TwDgpgBAggTnAhiAksCBbAPAFXkkKCAD3QDsATAZykTJAG0BdAPigF4o8FkjSJKNABQBLMgDMIcKAFEAlMygB+WVABcXfMgDcAKF2hIUNJhqcA3lHEB7axqrA4YgObaoAI0RwNZAK4Z3KSgAX2Y9Q2gAWRFiCAoTDDMoIUsbOygHJzJXDy8ff0DpYKgAMihLTwAvDQAhEWcUMnRnIOCFJj0DcGgRdAwOWB5UPqwEqhZw7qgMGLiEga1hzCxo2Pi+8cmjMQA3RAAbEQoFoYSsPwCpCaA
We've found this type handy in our codebase and thought this would be useful in
type-festtoo.Proposal
ArrayItemextracts the type of the item(s) in the array:Possibly could be improved by replacing the fallback conditional with
unknowninstead ofTArray.playground example: https://www.typescriptlang.org/play/#code/C4TwDgpgBAggTnAhiAksCBbAPAFXkkKCAD3QDsATAZykTJAG0BdAPigF4o8FkjSJKNABQBLMgDMIcKAFEAlMygB+WVABcXfMgDcAKF2hIUNJhqcA3lHEB7axqrA4YgObaoAI0RwNZAK4Z3KSgAX2Y9Q2gAWRFiCAoTDDMoIUsbOygHJzJXDy8ff0DpYKgAMihLTwAvDQAhEWcUMnRnIOCFJj0DcGgRdAwOWB5UPqwEqhZw7qgMGLiEga1hzCxo2Pi+8cmjMQA3RAAbEQoFoYSsPwCpCaA