Type alias ArrayLike<Item>

ArrayLike<Item>: {
    length: number;
    [index: number]: Item;
}

An alternative for TypeScript's ArrayLike type, with its type set to unknown by default.

Remarks

When working with optional types, having to type ArrayLike<unknown> every time gets annoying pretty fast. This type is a drop-in replacement for ArrayLike, with the only difference being that the type of the items is set to unknown by default.

Example

const arrayLike: ArrayLike<number> = [1, 2, 3];

Type Parameters

  • Item = unknown

    Type of the items in the array-like object.

Type declaration

  • [index: number]: Item
  • Readonly length: number

    Amount of items in the ArrayLike.