API reference › @evolu/common › Type › minEntries

function minEntries<Min extends number>(
  min: ValidateBrandFactoryCount<Min>,
): <ParentType>(
  parent: EntriesParent<`MinEntries${Min}`, ParentType>,
) => BrandType<ParentType, `MinEntries${Min}`, MinEntriesError<Min>>;

Defined in: packages/common/src/Type.ts:16418

Minimum entry count Brand for record and object Outputs with at least min entries.

Counts the own enumerable string keys of the Output, which are exactly the entries of a Record or Object Output. Absent optional properties are not counted. Array, typed array, DataView, Set, Map, ArrayBuffer, Date, and Function parents are rejected at compile time; use minLength for arrays.

Example

import {
  assertEqual,
  assertErr,
  assertOk,
  minEntries,
  Number,
  record,
  String,
} from "@evolu/common";

const Scores = minEntries(1)(record(String, Number));

assertOk(Scores.fromUnknown({ ada: 10 }), { ada: 10 });

const invalid = Scores.fromUnknown({});
assertErr(invalid, { type: "MinEntries1", value: {}, min: 1 });
assertEqual(
  Scores.formatError(invalid.error),
  "The value {} does not meet the minimum entry count of 1.",
);