Skip to content

Entries type ​

The [key, value] pairs of an object type, each key with its own value type: the precise type of Object.entries, which widens keys to string.

ts
import type { Entries } from 'utils';

Signature ​

ts
export type Entries<T> = { [K in keyof T]-?: [K, T[K]] }[keyof T][];

Parameters ​

NameDescription
TThe object type.

Example ​

ts
const pairs = Object.entries(limits) as Entries<Limits>;

Tests ​

Line coverage: 0 %.

  • ✅ pairs each key with its value type

Source ​

src/types/entries.ts (on GitHub)

Source code
ts
/**
 * The `[key, value]` pairs of an object type, each key with its own value type: the precise type of
 * `Object.entries`, which widens keys to `string`.
 *
 * @template T - The object type.
 * @example
 * const pairs = Object.entries(limits) as Entries<Limits>;
 */
export type Entries<T> = { [K in keyof T]-?: [K, T[K]] }[keyof T][];
Test file
ts
import type { Entries } from './entries';

describe('Entries', () => {
  it('pairs each key with its value type', () => {
    expectTypeOf<Entries<{ a: number; b: string }>>().toEqualTypeOf<(['a', number] | ['b', string])[]>();
  });
});

Keywords: entries, types, type

Generated from the JSDoc of the sources.