stack

Home > @infiniteobjects/type-utils > Entries

Entries type

A type to better handle Object.entries() types.

Signature:

export type Entries<T extends object> = {
    [K in keyof T]: [K, T[K]];
}[keyof T][];

Example

type ObjectType = { a: number, b: number, c: string }
const obj:ObjectType = { a: 1, b: 2, c: 3 }

for (const [key, value] of Object.entries(obj as Entries<ObjectType>)) {
 // key is inferred as "a" | "b" | "c"
 // value is inferred as number | string
}