Skip to content

Latest commit

 

History

History
52 lines (37 loc) · 806 Bytes

File metadata and controls

52 lines (37 loc) · 806 Bytes

typelab / aliases / ObjectArrayLike

type ObjectArrayLike<T> = Record<number, T>;

Extended TypeScript `Record` to define an object with number as key type.

Type Parameters

Type Parameter Default type Description

T

Any

The type of the values in the object, defaults to 'any'.

Returns

Record type with number as a key and T as a value

Example

// ObjArrayLike is { [x: number]: string; }
type ObjArrayLike = ObjectArrayLike<string>;

const Valid: ObjArrayLike = { 0: 'first', 1: 'second' };
const Invalid: ObjArrayLike = { 0: 'first', a: 'second' }; // a is invalid key