Skip to content

Latest commit

 

History

History
52 lines (37 loc) · 838 Bytes

File metadata and controls

52 lines (37 loc) · 838 Bytes

typelab / aliases / ObjectGeneric

type ObjectGeneric<T> = Record<PropertyKey, T>;

Extended TypeScript `Record` to define a generic object 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 PropertyKey as a key and T as a value

Example

// ObjNumber is { [x: string]: number; [x: number]: number; [x: symbol]: number; }
type ObjNumber = ObjectGeneric<number>;

const Valid: ObjNumber = { a: 1, b: 2 };
const Invalid: ObjNumber = { a: '1', b: '2' }; // Type 'string' is not assignable to type 'number'