typelab / utils / ArrayToObject
type ArrayToObject<T> = T extends ReadonlyArray ? _IfNotAnyOrNever<T, _ArrayToObject<T>> : never;Converts an Array or Tuple type into an object type with numeric keys.
- For a
Tuple, keys are theTupleindices and values are the corresponding elements. - For an
Array, the keys are numbers and values are theArrayelements.
| Type Parameter | Description |
|---|---|
|
|
The |
An object type where:
// { 0: string, 1: number }
type Result1 = ArrayToObject<[string, number]>;
// { [x: number]: string }
type Result2 = ArrayToObject<string[]>;
// never
type Never = ArrayToObject<any>;